HDK
|
#include <string_view.h>
Public Types | |
typedef char | charT |
typedef charT | value_type |
typedef const charT * | pointer |
typedef const charT * | const_pointer |
typedef const charT & | reference |
typedef const charT & | const_reference |
typedef const_pointer | const_iterator |
typedef const_iterator | iterator |
typedef std::reverse_iterator < const_iterator > | const_reverse_iterator |
typedef const_reverse_iterator | reverse_iterator |
typedef size_t | size_type |
typedef ptrdiff_t | difference_type |
typedef std::char_traits< charT > | traits |
Static Public Attributes | |
static const size_type | npos = ~size_type(0) |
A string_view
is a non-owning, non-copying, non-allocating reference to a sequence of characters. It encapsulates both a character pointer and a length.
A function that takes a string input (but does not need to alter the string in place) may use a string_view parameter and accept input that is any of char* (C string), string literal (constant char array), a std::string (C++ string), or OIIO ustring. For all of these cases, no extra allocations are performed, and no extra copies of the string contents are performed (as they would be, for example, if the function took a const std::string& argument but was passed a char* or string literal).
Furthermore, a function that returns a copy or a substring of one of its inputs (for example, a substr()-like function) may return a string_view rather than a std::string, and thus generate its return value without any allocation or copying. Upon assignment to a std::string or ustring, it will properly auto-convert.
There are two important caveats to using this class:
Definition at line 63 of file string_view.h.
typedef char string_view::charT |
Definition at line 65 of file string_view.h.
typedef const_pointer string_view::const_iterator |
Definition at line 71 of file string_view.h.
Definition at line 68 of file string_view.h.
Definition at line 70 of file string_view.h.
typedef std::reverse_iterator<const_iterator> string_view::const_reverse_iterator |
Definition at line 73 of file string_view.h.
typedef ptrdiff_t string_view::difference_type |
Definition at line 76 of file string_view.h.
typedef const_iterator string_view::iterator |
Definition at line 72 of file string_view.h.
Definition at line 67 of file string_view.h.
Definition at line 69 of file string_view.h.
typedef const_reverse_iterator string_view::reverse_iterator |
Definition at line 74 of file string_view.h.
typedef size_t string_view::size_type |
Definition at line 75 of file string_view.h.
typedef std::char_traits<charT> string_view::traits |
Definition at line 77 of file string_view.h.
typedef charT string_view::value_type |
Definition at line 66 of file string_view.h.
|
inlinenoexcept |
Default ctr.
Definition at line 81 of file string_view.h.
|
inlinenoexcept |
Copy ctr.
Definition at line 83 of file string_view.h.
Construct from char* and length.
Definition at line 85 of file string_view.h.
Construct from char*, use strlen to determine length.
Definition at line 87 of file string_view.h.
|
inlinenoexcept |
Construct from std::string. Remember that a string_view doesn't have its own copy of the characters, so don't use the string_view
after the original string has been destroyed or altered.
Definition at line 91 of file string_view.h.
Element access with bounds checking and exception if out of bounds.
Definition at line 152 of file string_view.h.
Definition at line 159 of file string_view.h.
|
inlinenoexcept |
Definition at line 130 of file string_view.h.
const char* string_view::c_str | ( | ) | const |
Explicitly request a 0-terminated string. USUALLY, this turns out to be just data(), with no significant added expense (because most uses of string_view are simple wrappers of C strings, C++ std::string, or ustring – all of which are 0-terminated). But in the more rare case that the string_view represents a non-0-terminated substring, it will force an allocation and copy underneath.
Caveats:
|
inlinenoexcept |
Definition at line 132 of file string_view.h.
|
inlinenoexcept |
Definition at line 133 of file string_view.h.
|
inlinenoexcept |
Definition at line 163 of file string_view.h.
|
inlinenoexcept |
Definition at line 187 of file string_view.h.
|
inlinenoexcept |
Definition at line 136 of file string_view.h.
|
inlinenoexcept |
Definition at line 137 of file string_view.h.
Definition at line 160 of file string_view.h.
|
inlinenoexcept |
Is the string_view empty, containing no characters?
Definition at line 146 of file string_view.h.
|
inlinenoexcept |
Definition at line 131 of file string_view.h.
|
inlinenoexcept |
Find the first occurrence of substring s in *this, starting at position pos.
Definition at line 203 of file string_view.h.
Find the first occurrence of character c in *this, starting at position pos.
Definition at line 214 of file string_view.h.
|
inlinenoexcept |
Definition at line 265 of file string_view.h.
Definition at line 272 of file string_view.h.
Definition at line 244 of file string_view.h.
|
inlinenoexcept |
Definition at line 248 of file string_view.h.
|
inlinenoexcept |
Definition at line 281 of file string_view.h.
Definition at line 289 of file string_view.h.
Definition at line 246 of file string_view.h.
|
inlinenoexcept |
Definition at line 256 of file string_view.h.
Definition at line 158 of file string_view.h.
Definition at line 141 of file string_view.h.
Definition at line 142 of file string_view.h.
|
inline |
Convert a string_view to a std::string
.
Definition at line 127 of file string_view.h.
|
inlinenoexcept |
Definition at line 120 of file string_view.h.
Element access of an individual character (beware: no bounds checking!).
Definition at line 150 of file string_view.h.
|
inlinenoexcept |
Definition at line 134 of file string_view.h.
Definition at line 164 of file string_view.h.
Definition at line 171 of file string_view.h.
|
inlinenoexcept |
Definition at line 135 of file string_view.h.
|
inlinenoexcept |
Find the last occurrence of substring s *this, but only those occurrences earlier than position pos.
Definition at line 224 of file string_view.h.
Find the last occurrence of character c in *this, but only those occurrences earlier than position pos.
Definition at line 235 of file string_view.h.
Definition at line 140 of file string_view.h.
|
inline |
Convert a string_view to a std::string
.
Definition at line 94 of file string_view.h.
|
inlinenoexcept |
Definition at line 178 of file string_view.h.
Definition at line 78 of file string_view.h.