diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/str.cpp | 21 | ||||
-rw-r--r-- | common/str.h | 2 |
2 files changed, 23 insertions, 0 deletions
diff --git a/common/str.cpp b/common/str.cpp index e8e73a32a2..ffb8c298b0 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -160,6 +160,16 @@ void String::deleteLastChar() { } } +void String::deleteChar(int p) +{ + if (p >= 0 && p < _len) { + ensureCapacity(_len - 1, true); + while (p++ < _len) + _str[p-1] = _str[p]; + _len--; + } +} + void String::clear() { if (_capacity) { @@ -172,6 +182,17 @@ void String::clear() } } +void String::insertChar(char c, int p) +{ + if (p >= 0 && p <= _len) { + ensureCapacity(++_len, true); + for (int i = _len; i > p; i--) { + _str[i] = _str[i-1]; + } + _str[p] = c; + } +} + void String::toLowercase() { if (_str == 0 || _len == 0) diff --git a/common/str.h b/common/str.h index 4c2a985d46..8ff84c3b5d 100644 --- a/common/str.h +++ b/common/str.h @@ -110,7 +110,9 @@ public: } void deleteLastChar(); + void deleteChar(int p); void clear(); + void insertChar(char c, int p); void toLowercase(); void toUppercase(); |