COMMON: Add methods to U32String to match String

This commit is contained in:
Eugene Sandulenko 2019-10-04 12:12:49 +02:00
parent 72a5d9d4ba
commit dbf56a3b29
2 changed files with 30 additions and 0 deletions

View file

@ -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);

View file

@ -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();