aboutsummaryrefslogtreecommitdiff
path: root/common/str.cpp
diff options
context:
space:
mode:
authorMax Horn2008-07-23 09:53:29 +0000
committerMax Horn2008-07-23 09:53:29 +0000
commitd5e2c6d4bf32d066948df8a8a2bd4730e473a1cc (patch)
tree72119a26d1c7baa968645776efc8de0dfe760f65 /common/str.cpp
parentf2919e735ab83544008a22a540cca9d7887dc6cd (diff)
downloadscummvm-rg350-d5e2c6d4bf32d066948df8a8a2bd4730e473a1cc.tar.gz
scummvm-rg350-d5e2c6d4bf32d066948df8a8a2bd4730e473a1cc.tar.bz2
scummvm-rg350-d5e2c6d4bf32d066948df8a8a2bd4730e473a1cc.zip
Fix String::trim to work right for shared strings; augemented test cases to cover this
svn-id: r33234
Diffstat (limited to 'common/str.cpp')
-rw-r--r--common/str.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/common/str.cpp b/common/str.cpp
index f7cb84aa05..1b857546a8 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -288,12 +288,14 @@ void String::insertChar(char c, uint32 p) {
}
void String::toLowercase() {
+ // Ensure that the string is not shared
ensureCapacity(_len, true);
for (uint32 i = 0; i < _len; ++i)
_str[i] = tolower(_str[i]);
}
void String::toUppercase() {
+ // Ensure that the string is not shared
ensureCapacity(_len, true);
for (uint32 i = 0; i < _len; ++i)
_str[i] = toupper(_str[i]);
@@ -367,6 +369,9 @@ void String::trim() {
if (_len == 0)
return;
+ // Ensure that the string is not shared
+ ensureCapacity(_len, true);
+
// Trim trailing whitespace
while (_len >= 1 && isspace(_str[_len-1]))
_len--;