Merge pull request #305 from TsudaKageyu/fix-string-upper

String::upper() no longer modifies the String itself
This commit is contained in:
Stephen F. Booth
2013-10-30 19:45:54 -07:00
2 changed files with 10 additions and 1 deletions

View File

@ -390,7 +390,7 @@ String String::upper() const
{
static const int shift = 'A' - 'a';
String s(*this);
String s(*d->data);
for(Iterator it = s.begin(); it != s.end(); ++it) {
if(*it >= 'a' && *it <= 'z')
*it = *it + shift;

View File

@ -43,6 +43,7 @@ class TestString : public CppUnit::TestFixture
CPPUNIT_TEST(testToInt);
CPPUNIT_TEST(testSubstr);
CPPUNIT_TEST(testNewline);
CPPUNIT_TEST(testUpper);
CPPUNIT_TEST_SUITE_END();
public:
@ -237,6 +238,14 @@ public:
CPPUNIT_ASSERT_EQUAL(L'\x0d', String(crlf)[3]);
CPPUNIT_ASSERT_EQUAL(L'\x0a', String(crlf)[4]);
}
void testUpper()
{
String s1 = "tagLIB 012 strING";
String s2 = s1.upper();
CPPUNIT_ASSERT_EQUAL(String("tagLIB 012 strING"), s1);
CPPUNIT_ASSERT_EQUAL(String("TAGLIB 012 STRING"), s2);
}
};