class StringPiece

Defined at line 61 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

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.

ICU 4.2

Public Members

static const int32_t npos

Public Methods

void StringPiece (const char * str)

Constructs from a NUL-terminated const char * pointer.

Parameters

str a NUL-terminated const char * pointer ICU 4.2
void StringPiece (const char8_t * str)

Constructs from a NUL-terminated const char8_t * pointer.

Parameters

str a NUL-terminated const char8_t * pointer ICU 67

Defined at line 85 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void StringPiece (std::nullptr_t p)

Constructs an empty StringPiece.

Needed for type disambiguation from multiple other overloads.

Parameters

p nullptr ICU 67

Defined at line 93 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void StringPiece (const std::string & str)

Constructs from a std::string.

ICU 4.2

Defined at line 99 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void StringPiece (const std::u8string & str)

Constructs from a std::u8string.

ICU 67

Defined at line 106 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

template <typename T, typename = std::enable_if_t<
                                    (std::is_same_v<decltype(T().data()), const char*>
                    #if defined(__cpp_char8_t)
                                        || std::is_same_v<decltype(T().data()), const char8_t*>
                    #endif
                                    ) &&
                                    std::is_same_v<decltype(T().size()), size_t>>>
void StringPiece (T str)

Defined at line 141 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void StringPiece (const char * offset, int32_t len)

Constructs from a const char * pointer and a specified length.

Parameters

offset a const char * pointer (need not be terminated)
len the length of the string; must be non-negative ICU 4.2

Defined at line 151 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void StringPiece (const char8_t * str, int32_t len)

Constructs from a const char8_t * pointer and a specified length.

Parameters

str a const char8_t * pointer (need not be terminated)
len the length of the string; must be non-negative ICU 67

Defined at line 159 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void StringPiece (const StringPiece & x, int32_t pos)

Substring of another StringPiece.

Parameters

x the other StringPiece
pos start position in x; must be non-negative and <= x.length(). ICU 4.2
void StringPiece (const StringPiece & x, int32_t pos, int32_t len)

Substring of another StringPiece.

Parameters

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. ICU 4.2
void StringPiece ()

Default constructor, creates an empty StringPiece.

ICU 4.2

Defined at line 71 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

std::string_view operator basic_string_view ()

Converts to a std::string_view().

Defined at line 185 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

const char * data ()

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

ICU 4.2

Defined at line 200 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void set (const char * str)

Reset the stringpiece to refer to new data.

Parameters

str a pointer to a NUL-terminated string. ICU 4.8
int32_t find (StringPiece needle, int32_t offset)

Searches the StringPiece for the given search string (needle);

Parameters

needle The string for which to search.
offset Where to start searching within this string (haystack).

Returns

The offset of needle in haystack, or -1 if not found.

ICU 67

int32_t compare (StringPiece other)

Compares this StringPiece with the other StringPiece, with semantics

similar to std::string::compare().

Parameters

other The string to compare to.

Returns

below zero if this

<

other; above zero if this > other; 0 if this == other.

ICU 67

int32_t size ()

Returns the string length. Same as length().

Returns

the string length

ICU 4.2

Defined at line 206 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

int32_t length ()

Returns the string length. Same as size().

Returns

the string length

ICU 4.2

Defined at line 212 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

UBool empty ()

Returns whether the string is empty.

Returns

true if the string is empty

ICU 4.2

Defined at line 218 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void clear ()

Sets to an empty string.

ICU 4.2

Defined at line 224 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void set (const char * xdata, int32_t len)

Reset the stringpiece to refer to new data.

Parameters

xdata pointer the new string data. Need not be nul terminated.
len the length of the new data ICU 4.8

Defined at line 232 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void set (const char8_t * xdata, int32_t len)

Resets the stringpiece to refer to new data.

Parameters

xdata pointer the new string data. Need not be NUL-terminated.
len the length of the new data ICU 67

Defined at line 248 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void set (const char8_t * str)

Resets the stringpiece to refer to new data.

Parameters

str a pointer to a NUL-terminated string. ICU 67

Defined at line 257 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void remove_prefix (int32_t n)

Removes the first n string units.

Parameters

n prefix length, must be non-negative and <=length() ICU 4.2

Defined at line 267 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

void remove_suffix (int32_t n)

Removes the last n string units.

Parameters

n suffix length, must be non-negative and <=length() ICU 4.2

Defined at line 282 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h

StringPiece substr (int32_t pos, int32_t len)

Returns a substring of this StringPiece.

Parameters

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.

Returns

the substring StringPiece

ICU 4.2

Defined at line 324 of file ../../third_party/icu/default/source/common/unicode/stringpiece.h