|
| StringPiece () |
| Default constructor, creates an empty StringPiece. More...
|
|
| StringPiece (const char *str) |
| Constructs from a NUL-terminated const char * pointer. More...
|
|
| StringPiece (const char8_t *str) |
| Constructs from a NUL-terminated const char8_t * pointer. More...
|
|
| StringPiece (std::nullptr_t p) |
| Constructs an empty StringPiece. More...
|
|
| StringPiece (const std::string &str) |
| Constructs from a std::string. More...
|
|
| StringPiece (const std::u8string &str) |
| Constructs from a std::u8string. 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 char8_t *str, int32_t len) |
| Constructs from a const char8_t * 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 | set (const char8_t *xdata, int32_t len) |
| Resets the stringpiece to refer to new data. More...
|
|
void | set (const char8_t *str) |
| Resets 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...
|
|
int32_t | find (StringPiece needle, int32_t offset) |
| Searches the StringPiece for the given search string (needle);. More...
|
|
int32_t | compare (StringPiece other) |
| Compares this StringPiece with the other StringPiece, with semantics similar to std::string::compare(). More...
|
|
StringPiece | substr (int32_t pos, int32_t len=npos) const |
| Returns a substring of this StringPiece. 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.
- Stable:
- ICU 4.2
Definition at line 60 of file stringpiece.h.
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>
icu::StringPiece::StringPiece |
( |
T |
str | ) |
|
|
inline |
Constructs from some other implementation of a string piece class, from any C++ record type that has these two methods:
struct OtherStringPieceClass {
};
const char * data() const
Returns the string pointer.
int32_t size() const
Returns the string length.
The other string piece class will typically be std::string_view from C++17 or absl::string_view from Abseil.
Starting with C++20, data() may also return a const char8_t* pointer, as from std::u8string_view.
- Parameters
-
str | the other string piece |
- Stable:
- ICU 65
Definition at line 140 of file stringpiece.h.
const char * icu::StringPiece::data |
( |
| ) |
const |
|
inline |
Returns the string pointer.
May be nullptr 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.
- Returns
- the string pointer
- Stable:
- ICU 4.2
Definition at line 189 of file stringpiece.h.