1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-17 10:52:46 +00:00

Convert SDL (mostly) to plStrings

This commit is contained in:
2012-11-18 16:49:39 -08:00
parent 188171235e
commit 49dfb4e546
45 changed files with 456 additions and 488 deletions

View File

@ -709,7 +709,7 @@ static bool ch_in_set(char ch, const char *set)
return false;
}
std::vector<plString> plString::Tokenize(const char *delims)
std::vector<plString> plString::Tokenize(const char *delims) const
{
std::vector<plString> result;
@ -733,7 +733,7 @@ std::vector<plString> plString::Tokenize(const char *delims)
}
//TODO: Not binary safe
std::vector<plString> plString::Split(const char *split, size_t maxSplits)
std::vector<plString> plString::Split(const char *split, size_t maxSplits) const
{
std::vector<plString> result;
@ -765,6 +765,30 @@ plString operator+(const plString &left, const plString &right)
return cat;
}
plString operator+(const plString &left, const char *right)
{
plString cat;
size_t rsize = strlen(right);
char *catstr = cat.fUtf8Buffer.CreateWritableBuffer(left.GetSize() + rsize);
memcpy(catstr, left.c_str(), left.GetSize());
memcpy(catstr + left.GetSize(), right, rsize);
catstr[cat.fUtf8Buffer.GetSize()] = 0;
return cat;
}
plString operator+(const char *left, const plString &right)
{
plString cat;
size_t lsize = strlen(left);
char *catstr = cat.fUtf8Buffer.CreateWritableBuffer(lsize + right.GetSize());
memcpy(catstr, left, lsize);
memcpy(catstr + lsize, right.c_str(), right.GetSize());
catstr[cat.fUtf8Buffer.GetSize()] = 0;
return cat;
}
plStringStream &plStringStream::append(const char *data, size_t length)
{
if (fLength + length > fBufSize) {

View File

@ -163,18 +163,15 @@ private:
public:
plString() { }
#ifndef PLSTRING_POLLUTE_ASCII_CAST
plString(const char *cstr) { IConvertFromUtf8(cstr, kSizeAuto); }
#endif
plString(const plString &copy) : fUtf8Buffer(copy.fUtf8Buffer) { }
plString(const plStringBuffer<char> &init) { operator=(init); }
#ifndef PLSTRING_POLLUTE_ASCII_CAST
plString &operator=(const char *cstr) { IConvertFromUtf8(cstr, kSizeAuto); return *this; }
#endif
plString &operator=(const plString &copy) { fUtf8Buffer = copy.fUtf8Buffer; return *this; }
plString &operator=(const plStringBuffer<char> &init);
plString &operator+=(const char *cstr) { return operator=(*this + cstr); }
plString &operator+=(const plString &str) { return operator=(*this + str); }
static inline plString FromUtf8(const char *utf8, size_t size = kSizeAuto)
@ -205,10 +202,8 @@ public:
return str;
}
#ifndef PLSTRING_POLLUTE_C_STR
const char *c_str(const char *substitute = "") const
{ return IsEmpty() ? substitute : fUtf8Buffer.GetData(); }
#endif
char CharAt(size_t position) const { return c_str()[position]; }
@ -263,8 +258,15 @@ public:
: strnicmp(c_str(), str, count);
}
int CompareI(const plString &str) const { return Compare(str, kCaseInsensitive); }
int CompareI(const char *str) const { return Compare(str, kCaseInsensitive); }
int CompareNI(const plString &str, size_t count) const { return CompareN(str, count, kCaseInsensitive); }
int CompareNI(const char *str, size_t count) const { return CompareN(str, count, kCaseInsensitive); }
bool operator<(const plString &other) const { return Compare(other) < 0; }
bool operator==(const char *other) const { return Compare(other) == 0; }
bool operator==(const plString &other) const { return Compare(other) == 0; }
bool operator!=(const char *other) const { return Compare(other) != 0; }
bool operator!=(const plString &other) const { return Compare(other) != 0; }
int Find(char ch, CaseSensitivity sense = kCaseSensitive) const;
@ -291,8 +293,8 @@ public:
// and Tokenize is that Tokenize never returns a blank string (it strips
// all delimiters and only returns the pieces left between them), whereas
// Split will split on a full string, returning whatever is left between.
std::vector<plString> Split(const char *split, size_t maxSplits = kSizeAuto);
std::vector<plString> Tokenize(const char *delims = " \t\r\n\f\v");
std::vector<plString> Split(const char *split, size_t maxSplits = kSizeAuto) const;
std::vector<plString> Tokenize(const char *delims = " \t\r\n\f\v") const;
public:
struct less
@ -423,9 +425,13 @@ public:
private:
friend plString operator+(const plString &left, const plString &right);
friend plString operator+(const plString &left, const char *right);
friend plString operator+(const char *left, const plString &right);
};
plString operator+(const plString &left, const plString &right);
plString operator+(const plString &left, const char *right);
plString operator+(const char *left, const plString &right);
class plStringStream