Browse Source

Add plString::Replace

Michael Hansen 12 years ago
parent
commit
0d949cc137
  1. 23
      Sources/Plasma/CoreLib/plString.cpp
  2. 2
      Sources/Plasma/CoreLib/plString.h

23
Sources/Plasma/CoreLib/plString.cpp

@ -674,6 +674,29 @@ plString plString::Substr(int start, size_t size) const
return sub;
}
plString plString::Replace(const char *from, const char *to) const
{
if (IsEmpty() || !from || !from[0])
return *this;
if (!to)
to = "";
plStringStream out;
const char *pstart = c_str();
const char *pnext;
size_t flen = strlen(from), tlen = strlen(to);
while (pnext = strstr(pstart, from)) {
out.append(pstart, pnext - pstart);
out.append(to, tlen);
pstart = pnext + flen;
}
if (*pstart)
out << pstart;
return out.GetString();
}
plString plString::ToUpper() const
{
// TODO: Unicode-aware case conversion

2
Sources/Plasma/CoreLib/plString.h

@ -288,6 +288,8 @@ public:
plString Left(size_t size) const { return Substr(0, size); }
plString Right(size_t size) const { return Substr(GetSize() - size, size); }
plString Replace(const char *from, const char *to) const;
// NOTE: Does Compare(blah, kCaseInsensitive) make more sense? If
// so, use that instead -- it's faster and more efficient!
plString ToUpper() const;

Loading…
Cancel
Save