ICU 66.0.1
66.0.1
|
A string-like object that points to a sized piece of memory. More...
#include <stringpiece.h>
Public Member Functions | |
StringPiece () | |
Default constructor, creates an empty StringPiece. More... | |
StringPiece (const char *str) | |
Constructs from a NUL-terminated const char * pointer. More... | |
StringPiece (const std::string &str) | |
Constructs from a std::string. More... | |
template<typename T , typename = typename std::enable_if< std::is_same<decltype(T().data()), const char*>::value && std::is_same<decltype(T().size()), size_t>::value>::type> | |
StringPiece (T str) | |
Constructs from some other implementation of a string piece class, from any C++ record type that has these two methods: More... | |
StringPiece (const char *offset, int32_t len) | |
Constructs from a const char * pointer and a specified length. More... | |
StringPiece (const StringPiece &x, int32_t pos) | |
Substring of another StringPiece. More... | |
StringPiece (const StringPiece &x, int32_t pos, int32_t len) | |
Substring of another StringPiece. More... | |
const char * | data () const |
Returns the string pointer. More... | |
int32_t | size () const |
Returns the string length. More... | |
int32_t | length () const |
Returns the string length. More... | |
UBool | empty () const |
Returns whether the string is empty. More... | |
void | clear () |
Sets to an empty string. More... | |
void | set (const char *xdata, int32_t len) |
Reset the stringpiece to refer to new data. More... | |
void | set (const char *str) |
Reset the stringpiece to refer to new data. More... | |
void | remove_prefix (int32_t n) |
Removes the first n string units. More... | |
void | remove_suffix (int32_t n) |
Removes the last n string units. More... | |
StringPiece | substr (int32_t pos, int32_t len=npos) const |
Returns a substring of this StringPiece. More... | |
Static Public Attributes | |
static const int32_t | npos |
Maximum integer, used as a default value for substring methods. More... | |
A string-like object that points to a sized piece of memory.
We provide non-explicit singleton constructors so users can pass in a "const char*" or a "string" wherever a "StringPiece" is expected.
Functions or methods may use StringPiece parameters to accept either a "const char*" or a "string" value that will be implicitly converted to a StringPiece.
Systematic usage of StringPiece is encouraged as it will reduce unnecessary conversions from "const char*" to "string" and back again.
Definition at line 60 of file stringpiece.h.
|
inline |
Default constructor, creates an empty StringPiece.
Definition at line 70 of file stringpiece.h.
icu::StringPiece::StringPiece | ( | const char * | str | ) |
Constructs from a NUL-terminated const char * pointer.
str | a NUL-terminated const char * pointer |
|
inline |
|
inline |
Constructs from some other implementation of a string piece class, from any C++ record type that has these two methods:
The other string piece class will typically be std::string_view from C++17 or absl::string_view from Abseil.
str | the other string piece |
Definition at line 107 of file stringpiece.h.
|
inline |
Constructs from a const char * pointer and a specified length.
offset | a const char * pointer (need not be terminated) |
len | the length of the string; must be non-negative |
Definition at line 116 of file stringpiece.h.
icu::StringPiece::StringPiece | ( | const StringPiece & | x, |
int32_t | pos | ||
) |
Substring of another StringPiece.
x | the other StringPiece |
pos | start position in x; must be non-negative and <= x.length(). |
icu::StringPiece::StringPiece | ( | const StringPiece & | x, |
int32_t | pos, | ||
int32_t | len | ||
) |
Substring of another StringPiece.
x | the other StringPiece |
pos | start position in x; must be non-negative and <= x.length(). |
len | length of the substring; must be non-negative and will be pinned to at most x.length() - pos. |
|
inline |
Sets to an empty string.
Definition at line 168 of file stringpiece.h.
References NULL.
|
inline |
Returns the string pointer.
May be NULL if it is empty.
data() may return a pointer to a buffer with embedded NULs, and the returned buffer may or may not be null terminated. Therefore it is typically a mistake to pass data() to a routine that expects a NUL terminated string.
Definition at line 144 of file stringpiece.h.
|
inline |
Returns whether the string is empty.
Definition at line 162 of file stringpiece.h.
|
inline |
Returns the string length.
Same as size().
Definition at line 156 of file stringpiece.h.
|
inline |
Removes the first n string units.
n | prefix length, must be non-negative and <=length() |
Definition at line 190 of file stringpiece.h.
|
inline |
Removes the last n string units.
n | suffix length, must be non-negative and <=length() |
Definition at line 205 of file stringpiece.h.
|
inline |
Reset the stringpiece to refer to new data.
xdata | pointer the new string data. Need not be nul terminated. |
len | the length of the new data |
Definition at line 176 of file stringpiece.h.
void icu::StringPiece::set | ( | const char * | str | ) |
Reset the stringpiece to refer to new data.
str | a pointer to a NUL-terminated string. |
|
inline |
Returns the string length.
Same as length().
Definition at line 150 of file stringpiece.h.
|
inline |
Returns a substring of this StringPiece.
pos | start position; must be non-negative and <= length(). |
len | length of the substring; must be non-negative and will be pinned to at most length() - pos. |
Definition at line 229 of file stringpiece.h.
References icu::operator==(), and U_EXPORT.
|
static |
Maximum integer, used as a default value for substring methods.
Definition at line 219 of file stringpiece.h.