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

wjpalenstijn at users.sourceforge.net wjpalenstijn at users.sourceforge.net
Tue Sep 7 13:40:44 CEST 2010


Revision: 52618
          http://scummvm.svn.sourceforge.net/scummvm/?rev=52618&view=rev
Author:   wjpalenstijn
Date:     2010-09-07 11:40:44 +0000 (Tue, 07 Sep 2010)

Log Message:
-----------
COMMON: Fix edge case for wildcard in matchString

Modified Paths:
--------------
    scummvm/trunk/common/str.cpp
    scummvm/trunk/test/common/str.h

Modified: scummvm/trunk/common/str.cpp
===================================================================
--- scummvm/trunk/common/str.cpp	2010-09-07 09:19:25 UTC (rev 52617)
+++ scummvm/trunk/common/str.cpp	2010-09-07 11:40:44 UTC (rev 52618)
@@ -691,9 +691,18 @@
 
 		switch (*pat) {
 		case '*':
-			// Record pattern / string position for backtracking
-			p = ++pat;
-			q = str;
+			if (*str) {
+				// Record pattern / string position for backtracking
+				p = ++pat;
+				q = str;
+			} else {
+				// If we've reached the end of str, we can't backtrack further
+				// NB: We can't simply check if pat also ended here, because
+				// the pattern might end with any number of *s.
+				++pat;
+				p = 0;
+				q = 0;
+			}
 			// If pattern ended with * -> match
 			if (!*pat)
 				return true;

Modified: scummvm/trunk/test/common/str.h
===================================================================
--- scummvm/trunk/test/common/str.h	2010-09-07 09:19:25 UTC (rev 52617)
+++ scummvm/trunk/test/common/str.h	2010-09-07 11:40:44 UTC (rev 52618)
@@ -310,6 +310,9 @@
 		TS_ASSERT(Common::matchString("monkey.s01",  "monkey.s*1"));
 		TS_ASSERT(!Common::matchString("monkey.s99",  "monkey.s*1"));
 		TS_ASSERT(Common::matchString("monkey.s101", "monkey.s*1"));
+
+		TS_ASSERT(!Common::String("").matchString("*_"));
+		TS_ASSERT(Common::String("a").matchString("a***"));
 	}
 
 	void test_string_printf() {


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