summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Base')
-rw-r--r--Swiften/Base/String.h4
-rw-r--r--Swiften/Base/UnitTest/StringTest.cpp12
2 files changed, 14 insertions, 2 deletions
diff --git a/Swiften/Base/String.h b/Swiften/Base/String.h
index 03d9029..b05edba 100644
--- a/Swiften/Base/String.h
+++ b/Swiften/Base/String.h
@@ -66,6 +66,10 @@ namespace Swift {
return data_.size() > 0 && data_[data_.size()-1] == c;
}
+ bool endsWith(const String& s) const {
+ return data_.substr(data_.size() - s.data_.size(), data_.npos) == s;
+ }
+
String getSubstring(size_t begin, size_t end) const {
return String(data_.substr(begin, end));
}
diff --git a/Swiften/Base/UnitTest/StringTest.cpp b/Swiften/Base/UnitTest/StringTest.cpp
index 32d04a6..eff7b80 100644
--- a/Swiften/Base/UnitTest/StringTest.cpp
+++ b/Swiften/Base/UnitTest/StringTest.cpp
@@ -34,11 +34,11 @@ class StringTest : public CppUnit::TestFixture
CPPUNIT_TEST(testContains);
CPPUNIT_TEST(testContainsFalse);
CPPUNIT_TEST(testContainsExact);
+ CPPUNIT_TEST(testEndsWith);
+ CPPUNIT_TEST(testEndsWith_DoesNotEndWith);
CPPUNIT_TEST_SUITE_END();
public:
- StringTest() {}
-
void testGetLength() {
String testling("xyz$xyz");
@@ -180,6 +180,14 @@ class StringTest : public CppUnit::TestFixture
CPPUNIT_ASSERT(String("abcde").contains(String("abcde")));
}
+ void testEndsWith() {
+ CPPUNIT_ASSERT(String("abcdef").endsWith("cdef"));
+ }
+
+ void testEndsWith_DoesNotEndWith() {
+ CPPUNIT_ASSERT(!String("abcdef").endsWith("ddef"));
+ }
+
};
CPPUNIT_TEST_SUITE_REGISTRATION(StringTest);