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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Oct 4 10:04:18 CEST 2007


Revision: 29154
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29154&view=rev
Author:   fingolfin
Date:     2007-10-04 01:04:18 -0700 (Thu, 04 Oct 2007)

Log Message:
-----------
Patch #1805208: move matchString to Common::Util

Modified Paths:
--------------
    scummvm/trunk/common/fs.cpp
    scummvm/trunk/common/util.cpp
    scummvm/trunk/common/util.h

Modified: scummvm/trunk/common/fs.cpp
===================================================================
--- scummvm/trunk/common/fs.cpp	2007-10-03 22:04:36 UTC (rev 29153)
+++ scummvm/trunk/common/fs.cpp	2007-10-04 08:04:18 UTC (rev 29154)
@@ -26,43 +26,6 @@
 #include "backends/fs/abstract-fs.h"
 #include "backends/fs/abstract-fs-factory.h"
 
-/**
- * Simple DOS-style pattern matching function (understands * and ? like used in DOS).
- * Taken from exult/files/listfiles.cc
- */
-static bool matchString(const char *str, const char *pat) {
-	const char *p = 0;
-	const char *q = 0;
-
-	for (;;) {
-		switch (*pat) {
-		case '*':
-			p = ++pat;
-			q = str;
-			break;
-
-		default:
-			if (*pat != *str) {
-				if (p) {
-					pat = p;
-					str = ++q;
-					if (!*str)
-						return !*pat;
-					break;
-				}
-				else
-					return false;
-			}
-			// fallthrough
-		case '?':
-			if (!*str)
-				return !*pat;
-			pat++;
-			str++;
-		}
-	}
-}
-
 FilesystemNode::FilesystemNode() {
 	_realNode = 0;
 	_refCount = 0;
@@ -233,25 +196,19 @@
 	return ((matches > 0) ? true : false);
 }
 
-// HACK HACK HACK
-extern const char *lastPathComponent(const Common::String &str);
-
 int FilesystemNode::lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const
 {
 	FSList entries;
 	FSList children;
 	int matches = 0;
 	dir.getChildren(entries, FilesystemNode::kListAll, hidden);
-
+	
 	//Breadth search (entries in the same level)
 	for (FSList::iterator entry = entries.begin(); entry != entries.end(); ++entry) {
 		if (entry->isDirectory()) {
 			children.push_back(*entry);
 		} else {
-			//TODO: here we assume all backends implement the lastPathComponent method. It is currently static,
-			//		so it might be a good idea to include it inside the backend class. This would enforce its
-			//		implementation by all ports.
-			if (matchString(lastPathComponent(entry->getPath()), filename.c_str())) {
+			if (Common::matchString(entry->getName().c_str(), filename.c_str())) {
 				results.push_back(*entry);
 				matches++;
 

Modified: scummvm/trunk/common/util.cpp
===================================================================
--- scummvm/trunk/common/util.cpp	2007-10-03 22:04:36 UTC (rev 29153)
+++ scummvm/trunk/common/util.cpp	2007-10-04 08:04:18 UTC (rev 29154)
@@ -61,6 +61,39 @@
 
 namespace Common {
 
+bool matchString(const char *str, const char *pat) {
+	const char *p = 0;
+	const char *q = 0;
+
+	for (;;) {
+		switch (*pat) {
+		case '*':
+			p = ++pat;
+			q = str;
+			break;
+
+		default:
+			if (*pat != *str) {
+				if (p) {
+					pat = p;
+					str = ++q;
+					if (!*str)
+						return !*pat;
+					break;
+				}
+				else
+					return false;
+			}
+			// fallthrough
+		case '?':
+			if (!*str)
+				return !*pat;
+			pat++;
+			str++;
+		}
+	}
+}
+
 //
 // Print hexdump of the data passed in
 //

Modified: scummvm/trunk/common/util.h
===================================================================
--- scummvm/trunk/common/util.h	2007-10-03 22:04:36 UTC (rev 29153)
+++ scummvm/trunk/common/util.h	2007-10-04 08:04:18 UTC (rev 29154)
@@ -53,6 +53,28 @@
 namespace Common {
 
 /**
+ * Simple DOS-style pattern matching function (understands * and ? like used in DOS).
+ * Taken from exult/files/listfiles.cc
+ * 
+ * Token meaning:
+ * 		"*": any character, any amount of times.
+ * 		"?": any character, only once.
+ * 
+ * Example strings/patterns:
+ * 		String: monkey.s??	 Pattern: monkey.s01 	=> true
+ *		String: monkey.s??	 Pattern: monkey.s101 	=> false
+ *		String: monkey.s?1	 Pattern: monkey.s99 	=> false
+ *		String: monkey.s*	 Pattern: monkey.s101 	=> true
+ *		String: monkey.s*1	 Pattern: monkey.s99 	=> false
+ * 
+ * @param str Text to be matched against the given pattern.
+ * @param pat Glob pattern.
+ * 
+ * @return true if str matches the pattern, false otherwise.
+ */
+bool matchString(const char *str, const char *pat);
+
+/**
  * Print a hexdump of the data passed in. The number of bytes per line is
  * customizable.
  * @param data	the data to be dumped


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