Go to the documentation of this file.
22 #ifndef __STRINGPIECE_H__
23 #define __STRINGPIECE_H__
32 #if U_SHOW_CPLUSPLUS_API
35 #include <type_traits>
78 #ifndef U_HIDE_DRAFT_API
79 #if defined(__cpp_char8_t) || defined(U_IN_DOXYGEN)
94 #endif // U_HIDE_DRAFT_API
101 : ptr_(str.data()), length_(static_cast<int32_t>(str.size())) { }
102 #ifndef U_HIDE_DRAFT_API
103 #if defined(__cpp_lib_char8_t) || defined(U_IN_DOXYGEN)
109 : ptr_(reinterpret_cast<const char*>(str.data())),
110 length_(static_cast<int32_t>(str.size())) { }
112 #endif // U_HIDE_DRAFT_API
136 template <
typename T,
137 typename =
typename std::enable_if<
138 (std::is_same<decltype(T().data()),
const char*>::value
139 #if defined(__cpp_char8_t)
140 || std::is_same<decltype(T().data()),
const char8_t*>::value
143 std::is_same<decltype(T().size()),
size_t>::value>::type>
145 : ptr_(
reinterpret_cast<const char*
>(str.data())),
146 length_(
static_cast<int32_t
>(str.size())) {}
154 StringPiece(
const char* offset, int32_t len) : ptr_(offset), length_(len) { }
155 #ifndef U_HIDE_DRAFT_API
156 #if defined(__cpp_char8_t) || defined(U_IN_DOXYGEN)
164 StringPiece(reinterpret_cast<const char*>(str), len) {}
166 #endif // U_HIDE_DRAFT_API
195 const char*
data()
const {
return ptr_; }
201 int32_t
size()
const {
return length_; }
207 int32_t
length()
const {
return length_; }
219 void clear() { ptr_ =
nullptr; length_ = 0; }
227 void set(
const char* xdata, int32_t len) { ptr_ = xdata; length_ = len; }
234 void set(
const char* str);
236 #ifndef U_HIDE_DRAFT_API
237 #if defined(__cpp_char8_t) || defined(U_IN_DOXYGEN)
244 inline void set(
const char8_t* xdata, int32_t len) {
245 set(
reinterpret_cast<const char*
>(xdata), len);
253 inline void set(
const char8_t* str) {
254 set(
reinterpret_cast<const char*
>(str));
257 #endif // U_HIDE_DRAFT_API
289 #ifndef U_HIDE_DRAFT_API
307 #endif // U_HIDE_DRAFT_API
336 operator==(
const StringPiece& x,
const StringPiece& y);
353 #endif // __STRINGPIECE_H__
Basic definitions for ICU, for both C and C++ APIs.
void set(const char8_t *xdata, int32_t len)
Resets the stringpiece to refer to new data.
StringPiece(const std::u8string &str)
Constructs from a std::u8string.
int8_t UBool
The ICU boolean type, a signed-byte integer.
StringPiece(const char8_t *str)
Constructs from a NUL-terminated const char8_t * pointer.
StringPiece(const char *offset, int32_t len)
Constructs from a const char * pointer and a specified length.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
StringPiece(std::nullptr_t p)
Constructs an empty StringPiece.
void remove_prefix(int32_t n)
Removes the first n string units.
StringPiece(const std::string &str)
Constructs from a std::string.
StringPiece(T str)
Constructs from some other implementation of a string piece class, from any C++ record type that has ...
void set(const char8_t *str)
Resets the stringpiece to refer to new data.
void set(const char *xdata, int32_t len)
Reset the stringpiece to refer to new data.
int32_t size() const
Returns the string length.
UBool empty() const
Returns whether the string is empty.
UMemory is the common ICU base class.
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
const char * data() const
Returns the string pointer.
C++ API: Central ICU header for including the C++ standard <string> header and for related definition...
void clear()
Sets to an empty string.
StringPiece()
Default constructor, creates an empty StringPiece.
StringPiece(const char8_t *str, int32_t len)
Constructs from a const char8_t * pointer and a specified length.
void remove_suffix(int32_t n)
Removes the last n string units.
static const int32_t npos
Maximum integer, used as a default value for substring methods.
int32_t length() const
Returns the string length.
C++ API: Common ICU base class UObject.
StringPiece substr(int32_t pos, int32_t len=npos) const
Returns a substring of this StringPiece.
A string-like object that points to a sized piece of memory.