HDK
|
#include <string_view.h>
Public Types | |
using | charT = char |
using | Traits = std::char_traits< charT > |
using | traits_type = Traits |
using | value_type = charT |
using | pointer = const charT * |
using | const_pointer = const charT * |
using | reference = const charT & |
using | const_reference = const charT & |
using | const_iterator = const_pointer |
using | iterator = const_iterator |
using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
using | reverse_iterator = const_reverse_iterator |
using | size_type = size_t |
using | difference_type = ptrdiff_t |
using | traits = std::char_traits< charT > |
Public Member Functions | |
constexpr | string_view () noexcept |
Default ctr. More... | |
constexpr | string_view (const string_view ©) |
Copy ctr. More... | |
constexpr | string_view (const charT *chars, size_t len) |
Construct from char* and length. More... | |
OIIO_CONSTEXPR17 | string_view (const charT *chars) |
Construct from char*, use strlen to determine length. More... | |
string_view (const std::string &str) noexcept | |
std::string | str () const |
Convert a string_view to a std::string . More... | |
const char * | c_str () const |
OIIO_CONSTEXPR14 string_view & | operator= (const string_view ©) noexcept=default |
operator std::string () const | |
Convert a string_view to a std::string . More... | |
constexpr iterator | begin () const noexcept |
constexpr iterator | end () const noexcept |
constexpr const_iterator | cbegin () const noexcept |
constexpr const_iterator | cend () const noexcept |
OIIO_CONSTEXPR17 reverse_iterator | rbegin () const noexcept |
OIIO_CONSTEXPR17 reverse_iterator | rend () const noexcept |
OIIO_CONSTEXPR17 const_reverse_iterator | crbegin () const noexcept |
OIIO_CONSTEXPR17 const_reverse_iterator | crend () const noexcept |
constexpr size_type | size () const noexcept |
constexpr size_type | length () const noexcept |
constexpr size_type | max_size () const noexcept |
constexpr bool | empty () const noexcept |
Is the string_view empty, containing no characters? More... | |
constexpr const_reference | operator[] (size_type pos) const |
OIIO_CONSTEXPR17 const_reference | at (size_t pos) const |
Element access with bounds checking and exception if out of bounds. More... | |
constexpr const_reference | front () const |
constexpr const_reference | back () const |
constexpr const_pointer | data () const noexcept |
OIIO_CONSTEXPR14 void | clear () noexcept |
OIIO_CONSTEXPR14 void | remove_prefix (size_type n) noexcept |
OIIO_CONSTEXPR14 void | remove_suffix (size_type n) noexcept |
OIIO_CONSTEXPR14 string_view | substr (size_type pos, size_type n=npos) const noexcept |
OIIO_CONSTEXPR17 int | compare (string_view x) const noexcept |
size_type | find (string_view s, size_t pos=0) const noexcept |
size_type | find (charT c, size_t pos=0) const noexcept |
size_type | rfind (string_view s, size_t pos=npos) const noexcept |
size_type | rfind (charT c, size_t pos=npos) const noexcept |
size_type | find_first_of (charT c, size_t pos=0) const noexcept |
size_type | find_last_of (charT c, size_t pos=npos) const noexcept |
size_type | find_first_of (string_view s, size_t pos=0) const noexcept |
size_type | find_last_of (string_view s, size_t pos=npos) const noexcept |
size_type | find_first_not_of (string_view s, size_t pos=0) const noexcept |
size_type | find_first_not_of (charT c, size_t pos=0) const noexcept |
size_type | find_last_not_of (string_view s, size_t pos=npos) const noexcept |
size_type | find_last_not_of (charT c, size_t pos=npos) const noexcept |
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 64 of file string_view.h.
using string_view::charT = char |
Definition at line 66 of file string_view.h.
using string_view::const_iterator = const_pointer |
Definition at line 74 of file string_view.h.
using string_view::const_pointer = const charT* |
Definition at line 71 of file string_view.h.
using string_view::const_reference = const charT& |
Definition at line 73 of file string_view.h.
using string_view::const_reverse_iterator = std::reverse_iterator<const_iterator> |
Definition at line 76 of file string_view.h.
using string_view::difference_type = ptrdiff_t |
Definition at line 79 of file string_view.h.
using string_view::iterator = const_iterator |
Definition at line 75 of file string_view.h.
using string_view::pointer = const charT* |
Definition at line 70 of file string_view.h.
using string_view::reference = const charT& |
Definition at line 72 of file string_view.h.
using string_view::reverse_iterator = const_reverse_iterator |
Definition at line 77 of file string_view.h.
using string_view::size_type = size_t |
Definition at line 78 of file string_view.h.
using string_view::Traits = std::char_traits<charT> |
Definition at line 67 of file string_view.h.
using string_view::traits = std::char_traits<charT> |
Definition at line 80 of file string_view.h.
using string_view::traits_type = Traits |
Definition at line 68 of file string_view.h.
using string_view::value_type = charT |
Definition at line 69 of file string_view.h.
|
inlinenoexcept |
Default ctr.
Definition at line 84 of file string_view.h.
|
inline |
Copy ctr.
Definition at line 87 of file string_view.h.
|
inline |
Construct from char* and length.
Definition at line 91 of file string_view.h.
|
inline |
Construct from char*, use strlen to determine length.
Definition at line 95 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 102 of file string_view.h.
|
inline |
Element access with bounds checking and exception if out of bounds.
Definition at line 162 of file string_view.h.
|
inline |
Definition at line 169 of file string_view.h.
Definition at line 140 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 142 of file string_view.h.
|
inlinenoexcept |
Definition at line 143 of file string_view.h.
|
inlinenoexcept |
Definition at line 173 of file string_view.h.
|
inlinenoexcept |
Definition at line 197 of file string_view.h.
|
inlinenoexcept |
Definition at line 146 of file string_view.h.
|
inlinenoexcept |
Definition at line 147 of file string_view.h.
|
inlinenoexcept |
Definition at line 170 of file string_view.h.
|
inlinenoexcept |
Is the string_view empty, containing no characters?
Definition at line 156 of file string_view.h.
Definition at line 141 of file string_view.h.
|
inlinenoexcept |
Find the first occurrence of substring s in *this, starting at position pos.
Definition at line 214 of file string_view.h.
Find the first occurrence of character c in *this, starting at position pos.
Definition at line 225 of file string_view.h.
|
inlinenoexcept |
Definition at line 276 of file string_view.h.
Definition at line 283 of file string_view.h.
Definition at line 255 of file string_view.h.
|
inlinenoexcept |
Definition at line 259 of file string_view.h.
|
inlinenoexcept |
Definition at line 292 of file string_view.h.
Definition at line 300 of file string_view.h.
Definition at line 257 of file string_view.h.
|
inlinenoexcept |
Definition at line 267 of file string_view.h.
|
inline |
Definition at line 168 of file string_view.h.
Definition at line 151 of file string_view.h.
Definition at line 152 of file string_view.h.
|
inline |
Convert a string_view to a std::string
.
Definition at line 137 of file string_view.h.
|
defaultnoexcept |
|
inline |
Element access of an individual character (beware: no bounds checking!).
Definition at line 160 of file string_view.h.
|
inlinenoexcept |
Definition at line 144 of file string_view.h.
|
inlinenoexcept |
Definition at line 174 of file string_view.h.
|
inlinenoexcept |
Definition at line 181 of file string_view.h.
|
inlinenoexcept |
Definition at line 145 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 235 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 246 of file string_view.h.
Definition at line 150 of file string_view.h.
|
inline |
Convert a string_view to a std::string
.
Definition at line 107 of file string_view.h.
|
inlinenoexcept |
Definition at line 188 of file string_view.h.
Definition at line 81 of file string_view.h.