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.cpp16
2 files changed, 20 insertions, 0 deletions
diff --git a/Swiften/Base/String.h b/Swiften/Base/String.h
index 0a5530c..7a6a9cc 100644
--- a/Swiften/Base/String.h
+++ b/Swiften/Base/String.h
@@ -94,6 +94,10 @@ namespace Swift {
return *this;
}
+ bool contains(const String& o) {
+ return data_.find(o.data_) != std::string::npos;
+ }
+
char operator[](size_t i) const {
return data_[i];
}
diff --git a/Swiften/Base/UnitTest/StringTest.cpp b/Swiften/Base/UnitTest/StringTest.cpp
index 6ad12fd..87e1a99 100644
--- a/Swiften/Base/UnitTest/StringTest.cpp
+++ b/Swiften/Base/UnitTest/StringTest.cpp
@@ -25,6 +25,9 @@ class StringTest : public CppUnit::TestFixture
CPPUNIT_TEST(testReplaceAll_MatchingReplace);
CPPUNIT_TEST(testGetLowerCase);
CPPUNIT_TEST(testSplit);
+ CPPUNIT_TEST(testContains);
+ CPPUNIT_TEST(testContainsFalse);
+ CPPUNIT_TEST(testContainsExact);
CPPUNIT_TEST_SUITE_END();
public:
@@ -158,6 +161,19 @@ class StringTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(String("def"), result[1]);
CPPUNIT_ASSERT_EQUAL(String("ghi"), result[2]);
}
+
+ void testContains() {
+ CPPUNIT_ASSERT(String("abcde").contains(String("bcd")));
+ }
+
+ void testContainsFalse() {
+ CPPUNIT_ASSERT(!String("abcde").contains(String("abcdef")));
+ }
+
+ void testContainsExact() {
+ CPPUNIT_ASSERT(String("abcde").contains(String("abcde")));
+ }
+
};
CPPUNIT_TEST_SUITE_REGISTRATION(StringTest);