[Scummvm-cvs-logs] SF.net SVN: scummvm:[41333] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sun Jun 7 15:04:03 CEST 2009


Revision: 41333
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41333&view=rev
Author:   fingolfin
Date:     2009-06-07 13:04:03 +0000 (Sun, 07 Jun 2009)

Log Message:
-----------
Added some new method variants to Common::String

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	2009-06-07 12:47:10 UTC (rev 41332)
+++ scummvm/trunk/common/str.cpp	2009-06-07 13:04:03 UTC (rev 41333)
@@ -294,6 +294,10 @@
 	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 @@
 	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 @@
 	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;

Modified: scummvm/trunk/common/str.h
===================================================================
--- scummvm/trunk/common/str.h	2009-06-07 12:47:10 UTC (rev 41332)
+++ scummvm/trunk/common/str.h	2009-06-07 13:04:03 UTC (rev 41333)
@@ -143,9 +143,13 @@
 	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;
 

Modified: scummvm/trunk/test/common/str.h
===================================================================
--- scummvm/trunk/test/common/str.h	2009-06-07 12:47:10 UTC (rev 41332)
+++ scummvm/trunk/test/common/str.h	2009-06-07 13:04:03 UTC (rev 41333)
@@ -190,6 +190,9 @@
 		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() {


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