22 #ifndef __STRINGPIECE_H__ 23 #define __STRINGPIECE_H__ 32 #if U_SHOW_CPLUSPLUS_API 35 #include <type_traits> 82 : ptr_(str.data()), length_(static_cast<int32_t>(str.size())) { }
83 #ifndef U_HIDE_DRAFT_API 103 template <
typename T,
104 typename =
typename std::enable_if<
105 std::is_same<decltype(T().data()),
const char*>::value &&
106 std::is_same<decltype(T().size()),
size_t>::value>::type>
108 : ptr_(str.data()), length_(static_cast<int32_t>(str.size())) {}
109 #endif // U_HIDE_DRAFT_API 116 StringPiece(
const char* offset, int32_t len) : ptr_(offset), length_(len) { }
144 const char*
data()
const {
return ptr_; }
150 int32_t
size()
const {
return length_; }
156 int32_t
length()
const {
return length_; }
176 void set(
const char* xdata, int32_t len) { ptr_ = xdata; length_ = len; }
183 void set(
const char* str);
259 #endif // __STRINGPIECE_H__ StringPiece(const char *offset, int32_t len)
Constructs from a const char * pointer and a specified length.
void remove_prefix(int32_t n)
Removes the first n string units.
int32_t size() const
Returns the string length.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UBool empty() const
Returns whether the string is empty.
StringPiece()
Default constructor, creates an empty StringPiece.
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 ...
UBool operator!=(const StringPiece &x, const StringPiece &y)
Global operator != for StringPiece.
#define NULL
Define NULL if necessary, to nullptr for C++ and to ((void *)0) for C.
C++ API: Central ICU header for including the C++ standard <string> header and for related definition...
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.
const char * data() const
Returns the string pointer.
void clear()
Sets to an empty string.
Basic definitions for ICU, for both C and C++ APIs.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside...
A string-like object that points to a sized piece of memory.
void remove_suffix(int32_t n)
Removes the last n string units.
UMemory is the common ICU base class.
static const int32_t npos
Maximum integer, used as a default value for substring methods.
int8_t UBool
The ICU boolean type.