[Scummvm-cvs-logs] SF.net SVN: scummvm:[38277] scummvm/trunk/common
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Sun Feb 15 19:45:53 CET 2009
Revision: 38277
http://scummvm.svn.sourceforge.net/scummvm/?rev=38277&view=rev
Author: fingolfin
Date: 2009-02-15 18:45:53 +0000 (Sun, 15 Feb 2009)
Log Message:
-----------
Merged internal 'matchPath' method of class Archive into global matchString function (via an optional 'path mode' in the latter). Also changed Archive::listMatchingMembers to use path mode when matching, just like FSDirectory::listMatchingMembers
Modified Paths:
--------------
scummvm/trunk/common/archive.cpp
scummvm/trunk/common/archive.h
scummvm/trunk/common/str.cpp
scummvm/trunk/common/str.h
Modified: scummvm/trunk/common/archive.cpp
===================================================================
--- scummvm/trunk/common/archive.cpp 2009-02-15 18:37:25 UTC (rev 38276)
+++ scummvm/trunk/common/archive.cpp 2009-02-15 18:45:53 UTC (rev 38277)
@@ -56,7 +56,7 @@
ArchiveMemberList::iterator it = allNames.begin();
for ( ; it != allNames.end(); ++it) {
- if ((*it)->getName().matchString(lowercasePattern)) {
+ if ((*it)->getName().matchString(lowercasePattern, true)) {
list.push_back(*it);
matches++;
}
@@ -210,57 +210,6 @@
_cached = true;
}
-bool matchPath(const char *str, const char *pat) {
- assert(str);
- assert(pat);
-
- const char *p = 0;
- const char *q = 0;
-
- for (;;) {
- if (*str == '/') {
- p = 0;
- q = 0;
- }
-
- switch (*pat) {
- case '*':
- // Record pattern / string possition for backtracking
- p = ++pat;
- q = str;
- // If pattern ended with * -> match
- if (!*pat)
- return true;
- break;
-
- default:
- if (*pat != *str) {
- if (p) {
- // No match, oops -> try to backtrack
- pat = p;
- str = ++q;
- if (!*str)
- return !*pat;
- break;
- }
- else
- return false;
- }
- if (!*str)
- return !*pat;
- pat++;
- str++;
- break;
-
- case '?':
- if (!*str || *str == '/')
- return !*pat;
- pat++;
- str++;
- }
- }
-}
-
int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const String &pattern) {
if (!_node.isDirectory())
return 0;
@@ -274,7 +223,7 @@
int matches = 0;
NodeCache::iterator it = _fileCache.begin();
for ( ; it != _fileCache.end(); ++it) {
- if (matchPath(it->_key.c_str(), lowercasePattern.c_str())) {
+ if (it->_key.matchString(lowercasePattern, true)) {
list.push_back(ArchiveMemberPtr(new FSNode(it->_value)));
matches++;
}
Modified: scummvm/trunk/common/archive.h
===================================================================
--- scummvm/trunk/common/archive.h 2009-02-15 18:37:25 UTC (rev 38276)
+++ scummvm/trunk/common/archive.h 2009-02-15 18:45:53 UTC (rev 38277)
@@ -26,7 +26,6 @@
#ifndef COMMON_ARCHIVE_H
#define COMMON_ARCHIVE_H
-//#include "common/fs.h"
#include "common/str.h"
#include "common/hash-str.h"
#include "common/list.h"
Modified: scummvm/trunk/common/str.cpp
===================================================================
--- scummvm/trunk/common/str.cpp 2009-02-15 18:37:25 UTC (rev 38276)
+++ scummvm/trunk/common/str.cpp 2009-02-15 18:45:53 UTC (rev 38277)
@@ -330,12 +330,12 @@
return strchr(c_str(), x) != NULL;
}
-bool String::matchString(const char *pat) const {
- return Common::matchString(c_str(), pat);
+bool String::matchString(const char *pat, bool pathMode) const {
+ return Common::matchString(c_str(), pat, pathMode);
}
-bool String::matchString(const String &pat) const {
- return Common::matchString(c_str(), pat.c_str());
+bool String::matchString(const String &pat, bool pathMode) const {
+ return Common::matchString(c_str(), pat.c_str(), pathMode);
}
void String::deleteLastChar() {
@@ -615,7 +615,7 @@
return result;
}
-bool matchString(const char *str, const char *pat) {
+bool matchString(const char *str, const char *pat, bool pathMode) {
assert(str);
assert(pat);
@@ -623,6 +623,13 @@
const char *q = 0;
for (;;) {
+ if (pathMode && *str == '/') {
+ p = 0;
+ q = 0;
+ if (*pat == '?')
+ return false;
+ }
+
switch (*pat) {
case '*':
// Record pattern / string possition for backtracking
Modified: scummvm/trunk/common/str.h
===================================================================
--- scummvm/trunk/common/str.h 2009-02-15 18:37:25 UTC (rev 38276)
+++ scummvm/trunk/common/str.h 2009-02-15 18:45:53 UTC (rev 38277)
@@ -166,11 +166,12 @@
*
* @param str Text to be matched against the given pattern.
* @param pat Glob pattern.
+ * @param pathMode Whether to use path mode, i.e., whether slashes must be matched explicitly.
*
* @return true if str matches the pattern, false otherwise.
*/
- bool matchString(const char *pat) const;
- bool matchString(const String &pat) const;
+ bool matchString(const char *pat, bool pathMode = false) const;
+ bool matchString(const String &pat, bool pathMode = false) const;
inline const char *c_str() const { return _str; }
@@ -306,10 +307,11 @@
*
* @param str Text to be matched against the given pattern.
* @param pat Glob pattern.
+ * @param pathMode Whether to use path mode, i.e., whether slashes must be matched explicitly.
*
* @return true if str matches the pattern, false otherwise.
*/
-bool matchString(const char *str, const char *pat);
+bool matchString(const char *str, const char *pat, bool pathMode = false);
class StringList : public Array<String> {
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