diff options
author | richiesams | 2013-06-19 17:27:05 -0500 |
---|---|---|
committer | richiesams | 2013-06-20 15:40:25 -0500 |
commit | e1ff60da7aa311793cc424f23495442756762ee8 (patch) | |
tree | ff1895515adf97eae9934a9a7026ee6db68ac706 /common/str.cpp | |
parent | 4401f40f7203f7aaa78c2e1c904c70902325436c (diff) | |
download | scummvm-rg350-e1ff60da7aa311793cc424f23495442756762ee8.tar.gz scummvm-rg350-e1ff60da7aa311793cc424f23495442756762ee8.tar.bz2 scummvm-rg350-e1ff60da7aa311793cc424f23495442756762ee8.zip |
COMMON: Add erase method to String class
Diffstat (limited to 'common/str.cpp')
-rw-r--r-- | common/str.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/common/str.cpp b/common/str.cpp index 5d647ee4f0..4a10792373 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -361,6 +361,25 @@ void String::deleteChar(uint32 p) { _size--; } +void String::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 String::clear() { decRefCount(_extern._refCount); |