diff options
-rw-r--r-- | common/ustr.cpp | 24 | ||||
-rw-r--r-- | common/ustr.h | 6 |
2 files changed, 30 insertions, 0 deletions
diff --git a/common/ustr.cpp b/common/ustr.cpp index c53c4286f7..3a78239cb6 100644 --- a/common/ustr.cpp +++ b/common/ustr.cpp @@ -232,6 +232,30 @@ void U32String::deleteChar(uint32 p) { _size--; } +void U32String::deleteLastChar() { + if (_size > 0) + deleteChar(_size - 1); +} + +void U32String::erase(uint32 p, uint32 len) { + assert(p < _size); + + makeUnique(); + // If len == npos or p + len is over the end, remove all the way to the end + if (len == npos || p + len >= _size) { + // Delete char at p as well. So _size = (p - 1) + 1 + _size = p; + // Null terminate + _str[_size] = 0; + return; + } + + for ( ; p + len <= _size; p++) { + _str[p] = _str[p + len]; + } + _size -= len; +} + void U32String::clear() { decRefCount(_extern._refCount); diff --git a/common/ustr.h b/common/ustr.h index 5205216044..431cd9694a 100644 --- a/common/ustr.h +++ b/common/ustr.h @@ -162,6 +162,12 @@ public: */ void deleteChar(uint32 p); + /** Remove the last character from the string. */ + void deleteLastChar(); + + /** Remove all characters from position p to the p + len. If len = String::npos, removes all characters to the end */ + void erase(uint32 p, uint32 len = npos); + /** Clears the string, making it empty. */ void clear(); |