HDK
|
#include <core.h>
Public Types | |
using | value_type = Char |
using | iterator = const Char * |
using | charT = 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 > |
using | string = std::basic_string< CharT, Traits > |
Public Member Functions | |
constexpr | basic_string_view () noexcept |
constexpr | basic_string_view (const Char *s, size_t count) noexcept |
FMT_CONSTEXPR_CHAR_TRAITS FMT_INLINE | basic_string_view (const Char *s) |
template<typename Traits , typename Alloc > | |
FMT_CONSTEXPR | basic_string_view (const std::basic_string< Char, Traits, Alloc > &s) noexcept |
template<typename S , FMT_ENABLE_IF(std::is_same< S, detail::std_string_view< Char >>::value) > | |
FMT_CONSTEXPR | basic_string_view (S s) noexcept |
constexpr auto | data () const noexcept-> const Char * |
constexpr auto | size () const noexcept-> size_t |
constexpr auto | begin () const noexcept-> iterator |
constexpr auto | end () const noexcept-> iterator |
constexpr auto | operator[] (size_t pos) const noexcept-> const Char & |
FMT_CONSTEXPR void | remove_prefix (size_t n) noexcept |
FMT_CONSTEXPR_CHAR_TRAITS bool | starts_with (basic_string_view< Char > sv) const noexcept |
FMT_CONSTEXPR_CHAR_TRAITS bool | starts_with (Char c) const noexcept |
FMT_CONSTEXPR_CHAR_TRAITS bool | starts_with (const Char *s) const |
FMT_CONSTEXPR_CHAR_TRAITS auto | compare (basic_string_view other) const -> int |
constexpr | basic_string_view () noexcept |
Default ctr. More... | |
constexpr | basic_string_view (const basic_string_view ©) |
Copy ctr. More... | |
constexpr | basic_string_view (const CharT *chars, size_t len) noexcept |
Construct from char* and length. More... | |
constexpr | basic_string_view (const CharT *chars) noexcept |
Construct from char*, use strlen to determine length. More... | |
basic_string_view (const string &str) noexcept | |
OIIO_CONSTEXPR20 string | str () const |
const CharT * | c_str () const |
OIIO_CONSTEXPR14 basic_string_view & | operator= (const basic_string_view ©) noexcept=default |
operator std::basic_string< CharT, Traits > () 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 basic_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 basic_string_view | substr (size_type pos, size_type n=npos) const noexcept |
OIIO_CONSTEXPR17 int | compare (basic_string_view x) const noexcept |
size_type | find (basic_string_view s, size_t pos=0) const noexcept |
size_type | find (CharT c, size_t pos=0) const noexcept |
size_type | rfind (basic_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 (basic_string_view s, size_t pos=0) const noexcept |
size_type | find_last_of (basic_string_view s, size_t pos=npos) const noexcept |
size_type | find_first_not_of (basic_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 (basic_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) |
An implementation of std::basic_string_view
for pre-C++17. It provides a subset of the API. fmt::basic_string_view
is used for format strings even if std::string_view
is available to prevent issues when a library is compiled with a different -std
option than the client code (which is not recommended).
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. This is analogous to C++17 std::string_view, but supports C++14.
Note: string_view
is an alias for basic_string_view<char>
.
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:
fopen(std::string(my_string_view).c_str())
. using basic_string_view< Char >::charT = CharT |
Definition at line 80 of file string_view.h.
using basic_string_view< Char >::const_iterator = const_pointer |
Definition at line 87 of file string_view.h.
using basic_string_view< Char >::const_pointer = const CharT* |
Definition at line 84 of file string_view.h.
using basic_string_view< Char >::const_reference = const CharT& |
Definition at line 86 of file string_view.h.
using basic_string_view< Char >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
Definition at line 89 of file string_view.h.
using basic_string_view< Char >::difference_type = ptrdiff_t |
Definition at line 92 of file string_view.h.
using basic_string_view< Char >::iterator = const_iterator |
Definition at line 88 of file string_view.h.
using basic_string_view< Char >::iterator = const Char* |
using basic_string_view< Char >::pointer = const CharT* |
Definition at line 83 of file string_view.h.
using basic_string_view< Char >::reference = const CharT& |
Definition at line 85 of file string_view.h.
using basic_string_view< Char >::reverse_iterator = const_reverse_iterator |
Definition at line 90 of file string_view.h.
using basic_string_view< Char >::size_type = size_t |
Definition at line 91 of file string_view.h.
using basic_string_view< Char >::string = std::basic_string<CharT, Traits> |
Definition at line 94 of file string_view.h.
using basic_string_view< Char >::traits = std::char_traits<CharT> |
Definition at line 93 of file string_view.h.
using basic_string_view< Char >::traits_type = Traits |
Definition at line 81 of file string_view.h.
using basic_string_view< Char >::value_type = CharT |
Definition at line 82 of file string_view.h.
using basic_string_view< Char >::value_type = Char |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
Constructs a string reference from a std::basic_string
object.
|
inlinenoexcept |
|
inlinenoexcept |
Default ctr.
Definition at line 98 of file string_view.h.
|
inline |
Copy ctr.
Definition at line 101 of file string_view.h.
|
inlinenoexcept |
Construct from char* and length.
Definition at line 105 of file string_view.h.
|
inlinenoexcept |
Construct from char*, use strlen to determine length.
Definition at line 109 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 115 of file string_view.h.
|
inline |
Element access with bounds checking and exception if out of bounds.
Definition at line 215 of file string_view.h.
|
inline |
Definition at line 222 of file string_view.h.
|
inlinenoexcept |
Definition at line 193 of file string_view.h.
|
inlinenoexcept |
const CharT* basic_string_view< Char >::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 195 of file string_view.h.
|
inlinenoexcept |
Definition at line 196 of file string_view.h.
|
inlinenoexcept |
Definition at line 226 of file string_view.h.
|
inlinenoexcept |
Definition at line 250 of file string_view.h.
|
inline |
|
inlinenoexcept |
Definition at line 199 of file string_view.h.
|
inlinenoexcept |
Definition at line 200 of file string_view.h.
|
inlinenoexcept |
Definition at line 223 of file string_view.h.
|
inlinenoexcept |
|
inlinenoexcept |
Is the basic_string_view empty, containing no characters?
Definition at line 209 of file string_view.h.
|
inlinenoexcept |
Definition at line 194 of file string_view.h.
|
inlinenoexcept |
|
inlinenoexcept |
Find the first occurrence of substring s in *this, starting at position pos.
Definition at line 267 of file string_view.h.
|
inlinenoexcept |
Find the first occurrence of character c in *this, starting at position pos.
Definition at line 278 of file string_view.h.
|
inlinenoexcept |
Definition at line 329 of file string_view.h.
|
inlinenoexcept |
Definition at line 336 of file string_view.h.
|
inlinenoexcept |
Definition at line 308 of file string_view.h.
|
inlinenoexcept |
Definition at line 312 of file string_view.h.
|
inlinenoexcept |
Definition at line 345 of file string_view.h.
|
inlinenoexcept |
Definition at line 353 of file string_view.h.
|
inlinenoexcept |
Definition at line 310 of file string_view.h.
|
inlinenoexcept |
Definition at line 320 of file string_view.h.
|
inline |
Definition at line 221 of file string_view.h.
|
inlinenoexcept |
Definition at line 204 of file string_view.h.
|
inlinenoexcept |
Definition at line 205 of file string_view.h.
|
inline |
Convert a string_view to a std::string
.
Definition at line 166 of file string_view.h.
|
defaultnoexcept |
|
inline |
Element access of an individual character (beware: no bounds checking!).
Definition at line 213 of file string_view.h.
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 197 of file string_view.h.
|
inlinenoexcept |
Definition at line 227 of file string_view.h.
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 234 of file string_view.h.
|
inlinenoexcept |
Definition at line 198 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 288 of file string_view.h.
|
inlinenoexcept |
Find the last occurrence of character c in *this, but only those occurrences earlier than position pos.
Definition at line 299 of file string_view.h.
|
inlinenoexcept |
Definition at line 203 of file string_view.h.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inline |
Convert a string_view to a std::string
. NOTE: the str()
method is not part of the C++17 std::string_view. If strict interchangeability with std::string_view is desired, you might prefer the equivalent idiom std::string(sv)
.
Definition at line 135 of file string_view.h.
|
inlinenoexcept |
Definition at line 241 of file string_view.h.
|
friend |
Definition at line 370 of file string_view.h.
|
friend |
|
friend |
Definition at line 376 of file string_view.h.
|
friend |
|
friend |
Definition at line 400 of file string_view.h.
|
friend |
Definition at line 388 of file string_view.h.
|
friend |
|
friend |
Definition at line 364 of file string_view.h.
|
friend |
|
friend |
Definition at line 382 of file string_view.h.
|
friend |
|
friend |
Definition at line 394 of file string_view.h.
|
friend |
|
static |
Definition at line 95 of file string_view.h.