mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 19:29:09 +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;
|
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
|
plString plString::ToUpper() const
|
||||||
{
|
{
|
||||||
// TODO: Unicode-aware case conversion
|
// TODO: Unicode-aware case conversion
|
||||||
|
@ -288,6 +288,8 @@ 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); }
|
||||||
|
|
||||||
|
plString Replace(const char *from, const char *to) const;
|
||||||
|
|
||||||
// NOTE: Does Compare(blah, kCaseInsensitive) make more sense? If
|
// NOTE: Does Compare(blah, kCaseInsensitive) make more sense? If
|
||||||
// so, use that instead -- it's faster and more efficient!
|
// so, use that instead -- it's faster and more efficient!
|
||||||
plString ToUpper() const;
|
plString ToUpper() const;
|
||||||
|
Reference in New Issue
Block a user