2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-14 02:27:40 -04:00

Add case conversion functionality

This commit is contained in:
2012-02-13 20:18:41 -08:00
committed by Adam Johnson
parent ccf5f59fda
commit 81465e621b
2 changed files with 35 additions and 0 deletions

View File

@ -644,6 +644,36 @@ plString plString::Substr(int start, size_t size) const
return str; return str;
} }
plString plString::ToUpper() const
{
// TODO: Unicode-aware case conversion
size_t size = GetSize();
char *dupe = new char[size + 1];
const char *self = c_str();
for (size_t i = 0; i < size; ++i)
dupe[i] = toupper(self[i]);
// Don't re-check UTF-8 on this
plString str;
str.fUtf8Buffer = plStringBuffer<char>::Steal(dupe, size);
return str;
}
plString plString::ToLower() const
{
// TODO: Unicode-aware case conversion
size_t size = GetSize();
char *dupe = new char[size + 1];
const char *self = c_str();
for (size_t i = 0; i < size; ++i)
dupe[i] = tolower(self[i]);
// Don't re-check UTF-8 on this
plString str;
str.fUtf8Buffer = plStringBuffer<char>::Steal(dupe, size);
return str;
}
plString &plString::operator+=(const plString &str) plString &plString::operator+=(const plString &str)
{ {
size_t catsize = GetSize() + str.GetSize(); size_t catsize = GetSize() + str.GetSize();

View File

@ -260,6 +260,11 @@ public:
plString Left(size_t size) const { return Substr(0, size); } plString Left(size_t size) const { return Substr(0, size); }
plString Right(size_t size) const { return Substr(GetSize() - size, size); } plString Right(size_t size) const { return Substr(GetSize() - size, size); }
// NOTE: Does ::Compare(blah, kCaseInsensitive) make more sense? If
// so, use that instead -- it's faster and more efficient!
plString ToUpper() const;
plString ToLower() const;
public: public:
struct less : public std::binary_function<plString, plString, bool> struct less : public std::binary_function<plString, plString, bool>
{ {