aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/str.cpp5
-rw-r--r--common/str.h4
-rw-r--r--test/common/str.h9
3 files changed, 16 insertions, 2 deletions
diff --git a/common/str.cpp b/common/str.cpp
index 31cbb7cd22..e5272bd133 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -211,6 +211,11 @@ bool String::hasSuffix(const char *x) const {
return *x == 0;
}
+bool String::contains(const char *x) const {
+ assert(x != 0);
+ return strstr(c_str(), x) != NULL;
+}
+
void String::deleteLastChar() {
deleteChar(_len - 1);
}
diff --git a/common/str.h b/common/str.h
index 16122b579f..9fbb6734f5 100644
--- a/common/str.h
+++ b/common/str.h
@@ -125,10 +125,10 @@ public:
int compareTo(const char *x) const; // strcmp clone
int compareToIgnoreCase(const char *x) const; // stricmp clone
-
-
bool hasSuffix(const char *x) const;
bool hasPrefix(const char *x) const;
+
+ bool contains(const char *x) const;
inline const char *c_str() const { return _str; }
inline uint size() const { return _len; }
diff --git a/test/common/str.h b/test/common/str.h
index 8b7b966935..2691a5420d 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -109,6 +109,15 @@ class StringTestSuite : public CxxTest::TestSuite
TS_ASSERT_EQUALS( str.hasSuffix("hahah"), false );
}
+ void test_contains( void )
+ {
+ Common::String str("this/is/a/test, haha");
+ TS_ASSERT_EQUALS( str.contains(""), true );
+ TS_ASSERT_EQUALS( str.contains("haha"), true );
+ TS_ASSERT_EQUALS( str.contains("hahb"), false );
+ TS_ASSERT_EQUALS( str.contains("test"), true );
+ }
+
void test_toLowercase( void )
{
Common::String str("Test it, NOW! 42");