aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/fs.cpp47
-rw-r--r--common/util.cpp33
-rw-r--r--common/util.h22
3 files changed, 57 insertions, 45 deletions
diff --git a/common/fs.cpp b/common/fs.cpp
index 7d7aa363fc..100f6c86bd 100644
--- a/common/fs.cpp
+++ b/common/fs.cpp
@@ -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 @@ bool FilesystemNode::lookupFile(FSList &results, FilesystemNode &dir, Common::St
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++;
diff --git a/common/util.cpp b/common/util.cpp
index 8bf704456a..eaef9ce0b5 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -61,6 +61,39 @@ extern bool isSmartphone(void);
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
//
diff --git a/common/util.h b/common/util.h
index f8f166e29e..2d55bf1fda 100644
--- a/common/util.h
+++ b/common/util.h
@@ -53,6 +53,28 @@ template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; }
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