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
svn-id: r38277
This commit is contained in:
parent
544bda60fa
commit
17014c4f47
4 changed files with 19 additions and 62 deletions
|
@ -56,7 +56,7 @@ int Archive::listMatchingMembers(ArchiveMemberList &list, const String &pattern)
|
||||||
|
|
||||||
ArchiveMemberList::iterator it = allNames.begin();
|
ArchiveMemberList::iterator it = allNames.begin();
|
||||||
for ( ; it != allNames.end(); ++it) {
|
for ( ; it != allNames.end(); ++it) {
|
||||||
if ((*it)->getName().matchString(lowercasePattern)) {
|
if ((*it)->getName().matchString(lowercasePattern, true)) {
|
||||||
list.push_back(*it);
|
list.push_back(*it);
|
||||||
matches++;
|
matches++;
|
||||||
}
|
}
|
||||||
|
@ -210,57 +210,6 @@ void FSDirectory::ensureCached() const {
|
||||||
_cached = true;
|
_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) {
|
int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const String &pattern) {
|
||||||
if (!_node.isDirectory())
|
if (!_node.isDirectory())
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -274,7 +223,7 @@ int FSDirectory::listMatchingMembers(ArchiveMemberList &list, const String &patt
|
||||||
int matches = 0;
|
int matches = 0;
|
||||||
NodeCache::iterator it = _fileCache.begin();
|
NodeCache::iterator it = _fileCache.begin();
|
||||||
for ( ; it != _fileCache.end(); ++it) {
|
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)));
|
list.push_back(ArchiveMemberPtr(new FSNode(it->_value)));
|
||||||
matches++;
|
matches++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#ifndef COMMON_ARCHIVE_H
|
#ifndef COMMON_ARCHIVE_H
|
||||||
#define COMMON_ARCHIVE_H
|
#define COMMON_ARCHIVE_H
|
||||||
|
|
||||||
//#include "common/fs.h"
|
|
||||||
#include "common/str.h"
|
#include "common/str.h"
|
||||||
#include "common/hash-str.h"
|
#include "common/hash-str.h"
|
||||||
#include "common/list.h"
|
#include "common/list.h"
|
||||||
|
|
|
@ -330,12 +330,12 @@ bool String::contains(char x) const {
|
||||||
return strchr(c_str(), x) != NULL;
|
return strchr(c_str(), x) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool String::matchString(const char *pat) const {
|
bool String::matchString(const char *pat, bool pathMode) const {
|
||||||
return Common::matchString(c_str(), pat);
|
return Common::matchString(c_str(), pat, pathMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool String::matchString(const String &pat) const {
|
bool String::matchString(const String &pat, bool pathMode) const {
|
||||||
return Common::matchString(c_str(), pat.c_str());
|
return Common::matchString(c_str(), pat.c_str(), pathMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void String::deleteLastChar() {
|
void String::deleteLastChar() {
|
||||||
|
@ -615,7 +615,7 @@ Common::String normalizePath(const Common::String &path, const char sep) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool matchString(const char *str, const char *pat) {
|
bool matchString(const char *str, const char *pat, bool pathMode) {
|
||||||
assert(str);
|
assert(str);
|
||||||
assert(pat);
|
assert(pat);
|
||||||
|
|
||||||
|
@ -623,6 +623,13 @@ bool matchString(const char *str, const char *pat) {
|
||||||
const char *q = 0;
|
const char *q = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
if (pathMode && *str == '/') {
|
||||||
|
p = 0;
|
||||||
|
q = 0;
|
||||||
|
if (*pat == '?')
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (*pat) {
|
switch (*pat) {
|
||||||
case '*':
|
case '*':
|
||||||
// Record pattern / string possition for backtracking
|
// Record pattern / string possition for backtracking
|
||||||
|
|
|
@ -166,11 +166,12 @@ public:
|
||||||
*
|
*
|
||||||
* @param str Text to be matched against the given pattern.
|
* @param str Text to be matched against the given pattern.
|
||||||
* @param pat Glob 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.
|
* @return true if str matches the pattern, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool matchString(const char *pat) const;
|
bool matchString(const char *pat, bool pathMode = false) const;
|
||||||
bool matchString(const String &pat) const;
|
bool matchString(const String &pat, bool pathMode = false) const;
|
||||||
|
|
||||||
|
|
||||||
inline const char *c_str() const { return _str; }
|
inline const char *c_str() const { return _str; }
|
||||||
|
@ -306,10 +307,11 @@ Common::String normalizePath(const Common::String &path, const char sep);
|
||||||
*
|
*
|
||||||
* @param str Text to be matched against the given pattern.
|
* @param str Text to be matched against the given pattern.
|
||||||
* @param pat Glob 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.
|
* @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> {
|
class StringList : public Array<String> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue