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:
@ -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
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user