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

Add plString::Replace

This commit is contained in:
2013-01-06 23:27:19 -08:00
parent ad6b0bf3c8
commit 0d949cc137
2 changed files with 25 additions and 0 deletions

View File

@ -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

View File

@ -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;