From e1ff60da7aa311793cc424f23495442756762ee8 Mon Sep 17 00:00:00 2001 From: richiesams Date: Wed, 19 Jun 2013 17:27:05 -0500 Subject: COMMON: Add erase method to String class --- common/str.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'common/str.cpp') 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); -- cgit v1.2.3