|
|
|
@ -57,6 +57,7 @@ typedef unsigned int UniChar;
|
|
|
|
|
#define SSO_CHARS (16) |
|
|
|
|
#define STRING_STACK_SIZE (256) |
|
|
|
|
#define WHITESPACE_CHARS " \t\n\r" |
|
|
|
|
#define STRLEN_AUTO (static_cast<size_t>(-1)) |
|
|
|
|
|
|
|
|
|
// Use "correct" stricmp based on the selected compiler / library
|
|
|
|
|
#if _MSC_VER |
|
|
|
@ -225,13 +226,6 @@ typedef plStringBuffer<UniChar> plUnicodeBuffer;
|
|
|
|
|
class plString |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
enum { |
|
|
|
|
/** Automatically determine the size of input (Requires input to be
|
|
|
|
|
* correctly null-terminated). |
|
|
|
|
*/ |
|
|
|
|
kSizeAuto = (size_t)(0x80000000) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** Represents a "null" plString object. */ |
|
|
|
|
static const plString Null; |
|
|
|
|
|
|
|
|
@ -261,7 +255,7 @@ public:
|
|
|
|
|
* \note This constructor expects the input to be UTF-8 encoded. For |
|
|
|
|
* conversion from ISO-8859-1 8-bit data, use FromIso8859_1(). |
|
|
|
|
*/ |
|
|
|
|
plString(const char *cstr, size_t size = kSizeAuto) { IConvertFromUtf8(cstr, size); } |
|
|
|
|
plString(const char *cstr, size_t size = STRLEN_AUTO) { IConvertFromUtf8(cstr, size); } |
|
|
|
|
|
|
|
|
|
/** Copy constructor. */ |
|
|
|
|
plString(const plString ©) : fUtf8Buffer(copy.fUtf8Buffer) { } |
|
|
|
@ -276,7 +270,7 @@ public:
|
|
|
|
|
plString(const plUnicodeBuffer &init) { IConvertFromUtf32(init.GetData(), init.GetSize()); } |
|
|
|
|
|
|
|
|
|
/** Assignment operator. Same as plString(const char *). */ |
|
|
|
|
plString &operator=(const char *cstr) { IConvertFromUtf8(cstr, kSizeAuto); return *this; } |
|
|
|
|
plString &operator=(const char *cstr) { IConvertFromUtf8(cstr, STRLEN_AUTO); return *this; } |
|
|
|
|
|
|
|
|
|
/** Assignment operator. Same as plString(const plString &). */ |
|
|
|
|
plString &operator=(const plString ©) { fUtf8Buffer = copy.fUtf8Buffer; return *this; } |
|
|
|
@ -299,7 +293,7 @@ public:
|
|
|
|
|
plString &operator+=(const plString &str) { return operator=(*this + str); } |
|
|
|
|
|
|
|
|
|
/** Create a new plString object from the UTF-8 formatted data in \a utf8. */ |
|
|
|
|
static inline plString FromUtf8(const char *utf8, size_t size = kSizeAuto) |
|
|
|
|
static inline plString FromUtf8(const char *utf8, size_t size = STRLEN_AUTO) |
|
|
|
|
{ |
|
|
|
|
plString str; |
|
|
|
|
str.IConvertFromUtf8(utf8, size); |
|
|
|
@ -307,7 +301,7 @@ public:
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** Create a new plString object from the UTF-16 formatted data in \a utf16. */ |
|
|
|
|
static inline plString FromUtf16(const uint16_t *utf16, size_t size = kSizeAuto) |
|
|
|
|
static inline plString FromUtf16(const uint16_t *utf16, size_t size = STRLEN_AUTO) |
|
|
|
|
{ |
|
|
|
|
plString str; |
|
|
|
|
str.IConvertFromUtf16(utf16, size); |
|
|
|
@ -315,7 +309,7 @@ public:
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** Create a new plString object from the \p wchar_t data in \a wstr. */ |
|
|
|
|
static inline plString FromWchar(const wchar_t *wstr, size_t size = kSizeAuto) |
|
|
|
|
static inline plString FromWchar(const wchar_t *wstr, size_t size = STRLEN_AUTO) |
|
|
|
|
{ |
|
|
|
|
plString str; |
|
|
|
|
str.IConvertFromWchar(wstr, size); |
|
|
|
@ -323,7 +317,7 @@ public:
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** Create a new plString object from the UTF-32 formatted data in \a utf32. */ |
|
|
|
|
static inline plString FromUtf32(const UniChar *utf32, size_t size = kSizeAuto) |
|
|
|
|
static inline plString FromUtf32(const UniChar *utf32, size_t size = STRLEN_AUTO) |
|
|
|
|
{ |
|
|
|
|
plString str; |
|
|
|
|
str.IConvertFromUtf32(utf32, size); |
|
|
|
@ -331,7 +325,7 @@ public:
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** Create a new plString object from the ISO-8859-1 formatted data in \a astr. */ |
|
|
|
|
static inline plString FromIso8859_1(const char *astr, size_t size = kSizeAuto) |
|
|
|
|
static inline plString FromIso8859_1(const char *astr, size_t size = STRLEN_AUTO) |
|
|
|
|
{ |
|
|
|
|
plString str; |
|
|
|
|
str.IConvertFromIso8859_1(astr, size); |
|
|
|
@ -552,7 +546,7 @@ public:
|
|
|
|
|
* number of characters left in the string after \a start, Substr will |
|
|
|
|
* return the remainder of the string. |
|
|
|
|
*/ |
|
|
|
|
plString Substr(ssize_t start, size_t size = kSizeAuto) const; |
|
|
|
|
plString Substr(ssize_t start, size_t size = STRLEN_AUTO) const; |
|
|
|
|
|
|
|
|
|
/** Return a substring containing at most \a size characters from the left
|
|
|
|
|
* of the string. Equivalent to Substr(0, size). |
|
|
|
@ -586,7 +580,7 @@ public:
|
|
|
|
|
* string in the returned vector. |
|
|
|
|
* \sa Tokenize() |
|
|
|
|
*/ |
|
|
|
|
std::vector<plString> Split(const char *split, size_t maxSplits = kSizeAuto) const; |
|
|
|
|
std::vector<plString> Split(const char *split, size_t maxSplits = (size_t)-1) const; |
|
|
|
|
|
|
|
|
|
/** Split this string into tokens, delimited by \a delims.
|
|
|
|
|
* Note that, unlike Split(), Tokenize will return only non-blank strings |
|
|
|
@ -740,6 +734,6 @@ private:
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** \p strlen implementation for UniChar based C-style string buffers. */ |
|
|
|
|
size_t ustrlen(const UniChar *ustr, size_t max = plString::kSizeAuto); |
|
|
|
|
size_t ustrlen(const UniChar *ustr); |
|
|
|
|
|
|
|
|
|
#endif //plString_Defined
|
|
|
|
|