Browse Source

Add case conversion functionality

Michael Hansen 13 years ago committed by Adam Johnson
parent
commit
81465e621b
  1. 30
      Sources/Plasma/CoreLib/plString.cpp
  2. 5
      Sources/Plasma/CoreLib/plString.h

30
Sources/Plasma/CoreLib/plString.cpp

@ -644,6 +644,36 @@ plString plString::Substr(int start, size_t size) const
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)
{
size_t catsize = GetSize() + str.GetSize();

5
Sources/Plasma/CoreLib/plString.h

@ -260,6 +260,11 @@ public:
plString Left(size_t size) const { return Substr(0, 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:
struct less : public std::binary_function<plString, plString, bool>
{

Loading…
Cancel
Save