[Scummvm-cvs-logs] SF.net SVN: scummvm:[33234] scummvm/trunk
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Wed Jul 23 11:53:30 CEST 2008
Revision: 33234
http://scummvm.svn.sourceforge.net/scummvm/?rev=33234&view=rev
Author: fingolfin
Date: 2008-07-23 09:53:29 +0000 (Wed, 23 Jul 2008)
Log Message:
-----------
Fix String::trim to work right for shared strings; augemented test cases to cover this
Modified Paths:
--------------
scummvm/trunk/common/str.cpp
scummvm/trunk/test/common/str.h
Modified: scummvm/trunk/common/str.cpp
===================================================================
--- scummvm/trunk/common/str.cpp 2008-07-23 09:45:44 UTC (rev 33233)
+++ scummvm/trunk/common/str.cpp 2008-07-23 09:53:29 UTC (rev 33234)
@@ -288,12 +288,14 @@
}
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 @@
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--;
Modified: scummvm/trunk/test/common/str.h
===================================================================
--- scummvm/trunk/test/common/str.h 2008-07-23 09:45:44 UTC (rev 33233)
+++ scummvm/trunk/test/common/str.h 2008-07-23 09:53:29 UTC (rev 33234)
@@ -7,55 +7,57 @@
public:
void test_constructors(void) {
Common::String str("test-string");
- TS_ASSERT( str == "test-string" );
+ TS_ASSERT( str == "test-string");
str = Common::String(str.c_str()+5, 3);
- TS_ASSERT( str == "str" );
+ TS_ASSERT( str == "str");
str = "test-string";
- TS_ASSERT( str == "test-string" );
+ TS_ASSERT( str == "test-string");
str = Common::String(str.c_str()+5, str.c_str()+8);
- TS_ASSERT( str == "str" );
+ TS_ASSERT( str == "str");
}
void test_trim(void) {
Common::String str(" This is a s tring with spaces ");
+ Common::String str2 = str;
str.trim();
- TS_ASSERT( str == "This is a s tring with spaces" );
+ TS_ASSERT( str == "This is a s tring with spaces");
+ TS_ASSERT( str2 == " This is a s tring with spaces ");
}
void test_empty_clear(void) {
Common::String str("test");
- TS_ASSERT( !str.empty() );
+ TS_ASSERT( !str.empty());
str.clear();
- TS_ASSERT( str.empty() );
+ TS_ASSERT( str.empty());
}
void test_lastChar(void) {
Common::String str;
- TS_ASSERT_EQUALS( str.lastChar(), '\0' );
+ TS_ASSERT_EQUALS(str.lastChar(), '\0');
str = "test";
- TS_ASSERT_EQUALS( str.lastChar(), 't' );
+ TS_ASSERT_EQUALS(str.lastChar(), 't');
Common::String str2("bar");
- TS_ASSERT_EQUALS( str2.lastChar(), 'r' );
+ TS_ASSERT_EQUALS(str2.lastChar(), 'r');
}
void test_concat1(void) {
Common::String str("foo");
Common::String str2("bar");
str += str2;
- TS_ASSERT_EQUALS( str, "foobar" );
- TS_ASSERT_EQUALS( str2, "bar" );
+ TS_ASSERT_EQUALS(str, "foobar");
+ TS_ASSERT_EQUALS(str2, "bar");
}
void test_concat2(void) {
Common::String str("foo");
str += "bar";
- TS_ASSERT_EQUALS( str, "foobar" );
+ TS_ASSERT_EQUALS(str, "foobar");
}
void test_concat3(void) {
Common::String str("foo");
str += 'X';
- TS_ASSERT_EQUALS( str, "fooX" );
+ TS_ASSERT_EQUALS(str, "fooX");
}
void test_refCount(void) {
@@ -63,9 +65,9 @@
Common::String foo2("foo");
Common::String foo3(foo2);
foo3 += 'X';
- TS_ASSERT_EQUALS( foo2, foo1 );
- TS_ASSERT_EQUALS( foo2, "foo" );
- TS_ASSERT_EQUALS( foo3, "foo""X" );
+ TS_ASSERT_EQUALS(foo2, foo1);
+ TS_ASSERT_EQUALS(foo2, "foo");
+ TS_ASSERT_EQUALS(foo3, "foo""X");
}
void test_refCount2(void) {
@@ -73,9 +75,9 @@
Common::String foo2("fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd");
Common::String foo3(foo2);
foo3 += 'X';
- TS_ASSERT_EQUALS( foo2, foo1 );
- TS_ASSERT_EQUALS( foo2, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd" );
- TS_ASSERT_EQUALS( foo3, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd""X" );
+ TS_ASSERT_EQUALS(foo2, foo1);
+ TS_ASSERT_EQUALS(foo2, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd");
+ TS_ASSERT_EQUALS(foo3, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd""X");
}
void test_refCount3(void) {
@@ -83,9 +85,9 @@
Common::String foo2("0123456789abcdefghijk");
Common::String foo3(foo2);
foo3 += "0123456789abcdefghijk";
- TS_ASSERT_EQUALS( foo2, foo1 );
- TS_ASSERT_EQUALS( foo2, "0123456789abcdefghijk" );
- TS_ASSERT_EQUALS( foo3, "0123456789abcdefghijk""0123456789abcdefghijk" );
+ TS_ASSERT_EQUALS(foo2, foo1);
+ TS_ASSERT_EQUALS(foo2, "0123456789abcdefghijk");
+ TS_ASSERT_EQUALS(foo3, "0123456789abcdefghijk""0123456789abcdefghijk");
}
void test_refCount4(void) {
@@ -93,44 +95,48 @@
Common::String foo2("fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd");
Common::String foo3(foo2);
foo3 += "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd";
- TS_ASSERT_EQUALS( foo2, foo1 );
- TS_ASSERT_EQUALS( foo2, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd" );
- TS_ASSERT_EQUALS( foo3, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd""fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd" );
+ TS_ASSERT_EQUALS(foo2, foo1);
+ TS_ASSERT_EQUALS(foo2, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd");
+ TS_ASSERT_EQUALS(foo3, "fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd""fooasdkadklasdjklasdjlkasjdlkasjdklasjdlkjasdasd");
}
void test_hasPrefix(void) {
Common::String str("this/is/a/test, haha");
- TS_ASSERT_EQUALS( str.hasPrefix(""), true );
- TS_ASSERT_EQUALS( str.hasPrefix("this"), true );
- TS_ASSERT_EQUALS( str.hasPrefix("thit"), false );
- TS_ASSERT_EQUALS( str.hasPrefix("foo"), false );
+ TS_ASSERT_EQUALS(str.hasPrefix(""), true);
+ TS_ASSERT_EQUALS(str.hasPrefix("this"), true);
+ TS_ASSERT_EQUALS(str.hasPrefix("thit"), false);
+ TS_ASSERT_EQUALS(str.hasPrefix("foo"), false);
}
void test_hasSuffix(void) {
Common::String str("this/is/a/test, haha");
- TS_ASSERT_EQUALS( str.hasSuffix(""), true );
- TS_ASSERT_EQUALS( str.hasSuffix("haha"), true );
- TS_ASSERT_EQUALS( str.hasSuffix("hahb"), false );
- TS_ASSERT_EQUALS( str.hasSuffix("hahah"), false );
+ TS_ASSERT_EQUALS(str.hasSuffix(""), true);
+ TS_ASSERT_EQUALS(str.hasSuffix("haha"), true);
+ TS_ASSERT_EQUALS(str.hasSuffix("hahb"), false);
+ TS_ASSERT_EQUALS(str.hasSuffix("hahah"), false);
}
void test_contains(void) {
Common::String str("this/is/a/test, haha");
- TS_ASSERT_EQUALS( str.contains(""), true );
- TS_ASSERT_EQUALS( str.contains("haha"), true );
- TS_ASSERT_EQUALS( str.contains("hahb"), false );
- TS_ASSERT_EQUALS( str.contains("test"), true );
+ TS_ASSERT_EQUALS(str.contains(""), true);
+ TS_ASSERT_EQUALS(str.contains("haha"), true);
+ TS_ASSERT_EQUALS(str.contains("hahb"), false);
+ TS_ASSERT_EQUALS(str.contains("test"), true);
}
void test_toLowercase(void) {
Common::String str("Test it, NOW! 42");
+ Common::String str2 = str;
str.toLowercase();
- TS_ASSERT_EQUALS( str, "test it, now! 42" );
+ TS_ASSERT_EQUALS(str, "test it, now! 42");
+ TS_ASSERT_EQUALS(str2, "Test it, NOW! 42");
}
void test_toUppercase(void) {
Common::String str("Test it, NOW! 42");
+ Common::String str2 = str;
str.toUppercase();
- TS_ASSERT_EQUALS( str, "TEST IT, NOW! 42" );
+ TS_ASSERT_EQUALS(str, "TEST IT, NOW! 42");
+ TS_ASSERT_EQUALS(str2, "Test it, NOW! 42");
}
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list