[Scummvm-cvs-logs] SF.net SVN: scummvm: [26514] scummvm/trunk
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Sun Apr 15 20:27:11 CEST 2007
Revision: 26514
http://scummvm.svn.sourceforge.net/scummvm/?rev=26514&view=rev
Author: fingolfin
Date: 2007-04-15 11:27:10 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
Added Common::String::contains() method
Modified Paths:
--------------
scummvm/trunk/common/str.cpp
scummvm/trunk/common/str.h
scummvm/trunk/test/common/str.h
Modified: scummvm/trunk/common/str.cpp
===================================================================
--- scummvm/trunk/common/str.cpp 2007-04-15 17:26:07 UTC (rev 26513)
+++ scummvm/trunk/common/str.cpp 2007-04-15 18:27:10 UTC (rev 26514)
@@ -211,6 +211,11 @@
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);
}
Modified: scummvm/trunk/common/str.h
===================================================================
--- scummvm/trunk/common/str.h 2007-04-15 17:26:07 UTC (rev 26513)
+++ scummvm/trunk/common/str.h 2007-04-15 18:27:10 UTC (rev 26514)
@@ -125,10 +125,10 @@
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; }
Modified: scummvm/trunk/test/common/str.h
===================================================================
--- scummvm/trunk/test/common/str.h 2007-04-15 17:26:07 UTC (rev 26513)
+++ scummvm/trunk/test/common/str.h 2007-04-15 18:27:10 UTC (rev 26514)
@@ -109,6 +109,15 @@
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");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list