diff options
author | Max Horn | 2009-06-07 13:04:03 +0000 |
---|---|---|
committer | Max Horn | 2009-06-07 13:04:03 +0000 |
commit | a39048877a0db397e8412e722af296e7c49643de (patch) | |
tree | aaab76676aac9f9449bca183547eeb5b146cdd98 | |
parent | 985bc454b20f20f2eccb62a2f3000022ac0d2c99 (diff) | |
download | scummvm-rg350-a39048877a0db397e8412e722af296e7c49643de.tar.gz scummvm-rg350-a39048877a0db397e8412e722af296e7c49643de.tar.bz2 scummvm-rg350-a39048877a0db397e8412e722af296e7c49643de.zip |
Added some new method variants to Common::String
svn-id: r41333
-rw-r--r-- | common/str.cpp | 12 | ||||
-rw-r--r-- | common/str.h | 4 | ||||
-rw-r--r-- | test/common/str.h | 3 |
3 files changed, 19 insertions, 0 deletions
diff --git a/common/str.cpp b/common/str.cpp index 3a3b1e610c..75394fcf89 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -294,6 +294,10 @@ String &String::operator +=(char c) { return *this; } +bool String::hasPrefix(const String &x) const { + return hasPrefix(x.c_str()); +} + bool String::hasPrefix(const char *x) const { assert(x != 0); // Compare x with the start of _str. @@ -307,6 +311,10 @@ bool String::hasPrefix(const char *x) const { return *x == 0; } +bool String::hasSuffix(const String &x) const { + return hasSuffix(x.c_str()); +} + bool String::hasSuffix(const char *x) const { assert(x != 0); // Compare x with the end of _str. @@ -323,6 +331,10 @@ bool String::hasSuffix(const char *x) const { return *x == 0; } +bool String::contains(const String &x) const { + return strstr(c_str(), x.c_str()) != NULL; +} + bool String::contains(const char *x) const { assert(x != 0); return strstr(c_str(), x) != NULL; diff --git a/common/str.h b/common/str.h index 4dc0f1be92..b7dbd6535a 100644 --- a/common/str.h +++ b/common/str.h @@ -143,9 +143,13 @@ public: int compareTo(const char *x) const; // strcmp clone int compareToIgnoreCase(const char *x) const; // stricmp clone + bool hasSuffix(const String &x) const; bool hasSuffix(const char *x) const; + + bool hasPrefix(const String &x) const; bool hasPrefix(const char *x) const; + bool contains(const String &x) const; bool contains(const char *x) const; bool contains(char x) const; diff --git a/test/common/str.h b/test/common/str.h index 1e92dc0b7f..bf0db98b09 100644 --- a/test/common/str.h +++ b/test/common/str.h @@ -190,6 +190,9 @@ class StringTestSuite : public CxxTest::TestSuite TS_ASSERT_EQUALS(str.contains("haha"), true); TS_ASSERT_EQUALS(str.contains("hahb"), false); TS_ASSERT_EQUALS(str.contains("test"), true); + + TS_ASSERT_EQUALS(str.contains('/'), true); + TS_ASSERT_EQUALS(str.contains('x'), false); } void test_toLowercase() { |