summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Base')
-rw-r--r--Swiften/Base/String.cpp18
-rw-r--r--Swiften/Base/String.h7
-rw-r--r--Swiften/Base/UnitTest/StringTest.cpp28
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();