aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorEugene Sandulenko2019-10-04 12:12:49 +0200
committerEugene Sandulenko2019-10-04 15:54:48 +0200
commitdbf56a3b2954330813a47ff86dae17831f9980a6 (patch)
tree06db2419f7c91057043a7a5a69570624d1ed8600 /common
parent72a5d9d4baa569c4f3904fd8180a07da937090ed (diff)
downloadscummvm-rg350-dbf56a3b2954330813a47ff86dae17831f9980a6.tar.gz
scummvm-rg350-dbf56a3b2954330813a47ff86dae17831f9980a6.tar.bz2
scummvm-rg350-dbf56a3b2954330813a47ff86dae17831f9980a6.zip
COMMON: Add methods to U32String to match String
Diffstat (limited to 'common')
-rw-r--r--common/ustr.cpp24
-rw-r--r--common/ustr.h6
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();