diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-02-14 17:58:02 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-02-14 21:36:30 (GMT) |
commit | cad974b45c0fb9355e68d9728e42c9ae3dbcebc7 (patch) | |
tree | 5c3a874d6e28b297aad599656743a79ec74c94c5 /Swiften/Base | |
parent | de84b90c52a1f367b31eb56beea56c0dceae43f5 (diff) | |
download | swift-cad974b45c0fb9355e68d9728e42c9ae3dbcebc7.zip swift-cad974b45c0fb9355e68d9728e42c9ae3dbcebc7.tar.bz2 |
String refactoring.
Removed String::getLength().
Rewrote String::removeAll().
Diffstat (limited to 'Swiften/Base')
-rw-r--r-- | Swiften/Base/String.cpp | 18 | ||||
-rw-r--r-- | Swiften/Base/String.h | 7 | ||||
-rw-r--r-- | Swiften/Base/UnitTest/StringTest.cpp | 28 |
3 files changed, 4 insertions, 49 deletions
diff --git a/Swiften/Base/String.cpp b/Swiften/Base/String.cpp index 17d49c2..460df36 100644 --- a/Swiften/Base/String.cpp +++ b/Swiften/Base/String.cpp @@ -69,24 +69,6 @@ std::pair<String,String> String::getSplittedAtFirst(char c) const { } } -size_t String::getLength() const { - size_t size = 0, current = 0, end = data_.size(); - while (current < end) { - size++; - current += sequenceLength(data_[current]); - } - return size; -} - -void String::removeAll(char c) { - size_t lastPos = 0; - size_t matchingIndex = 0; - while ((matchingIndex = data_.find(c, lastPos)) != data_.npos) { - data_.erase(matchingIndex, 1); - lastPos = matchingIndex; - } -} - void String::replaceAll(char c, const String& s) { size_t lastPos = 0; size_t matchingIndex = 0; diff --git a/Swiften/Base/String.h b/Swiften/Base/String.h index c87d82b..7d2f928 100644 --- a/Swiften/Base/String.h +++ b/Swiften/Base/String.h @@ -13,6 +13,7 @@ #include <utility> #include <vector> #include <cassert> +#include <algorithm> #define SWIFTEN_STRING_TO_CFSTRING(a) \ CFStringCreateWithBytes(NULL, reinterpret_cast<const UInt8*>(a.getUTF8Data()), a.getUTF8Size(), kCFStringEncodingUTF8, false) @@ -48,13 +49,13 @@ namespace Swift { std::vector<String> split(char c) const; - size_t getLength() const; - String getLowerCase() const { return boost::to_lower_copy(data_); } - void removeAll(char c); + void removeAll(char c) { + data_.erase(std::remove(data_.begin(), data_.end(), c), data_.end()); + } void replaceAll(char c, const String& s); diff --git a/Swiften/Base/UnitTest/StringTest.cpp b/Swiften/Base/UnitTest/StringTest.cpp index eff7b80..161b4f1 100644 --- a/Swiften/Base/UnitTest/StringTest.cpp +++ b/Swiften/Base/UnitTest/StringTest.cpp @@ -14,10 +14,6 @@ using namespace Swift; class StringTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(StringTest); - CPPUNIT_TEST(testGetLength); - CPPUNIT_TEST(testGetLength_EncodedLength2); - CPPUNIT_TEST(testGetLength_EncodedLength3); - CPPUNIT_TEST(testGetLength_EncodedLength4); CPPUNIT_TEST(testGetUnicodeCodePoints); CPPUNIT_TEST(testGetSplittedAtFirst); CPPUNIT_TEST(testGetSplittedAtFirst_CharacterAtEnd); @@ -39,30 +35,6 @@ class StringTest : public CppUnit::TestFixture CPPUNIT_TEST_SUITE_END(); public: - void testGetLength() { - String testling("xyz$xyz"); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(7), testling.getLength()); - } - - void testGetLength_EncodedLength2() { - String testling("xyz\xC2\xA2xyz"); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(7), testling.getLength()); - } - - void testGetLength_EncodedLength3() { - String testling("xyz\xE2\x82\xACxyz"); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(7), testling.getLength()); - } - - void testGetLength_EncodedLength4() { - String testling("xyz\xf4\x8a\xaf\x8dxyz"); - - CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(7), testling.getLength()); - } - void testGetUnicodeCodePoints() { String testling("$\xc2\xa2\xe2\x82\xac\xf4\x8a\xaf\x8d"); std::vector<unsigned int> points = testling.getUnicodeCodePoints(); |