aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schickel2016-01-26 02:20:52 +0100
committerJohannes Schickel2016-01-26 16:35:30 +0100
commit06641f29a7bdcda280b0291f215193f055c83969 (patch)
tree3ccd88990da40fa4c0a073e8311806bc863c4d39
parent6e95d092f5a8c313d51079b5107ebfab0ce78552 (diff)
downloadscummvm-rg350-06641f29a7bdcda280b0291f215193f055c83969.tar.gz
scummvm-rg350-06641f29a7bdcda280b0291f215193f055c83969.tar.bz2
scummvm-rg350-06641f29a7bdcda280b0291f215193f055c83969.zip
COMMON: Allow '#' to only match digits in matchString.
-rw-r--r--common/str.cpp7
-rw-r--r--common/str.h6
-rw-r--r--test/common/str.h3
3 files changed, 16 insertions, 0 deletions
diff --git a/common/str.cpp b/common/str.cpp
index faf84d722f..ae3a965c70 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -751,6 +751,13 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod
return true;
break;
+ case '#':
+ if (!isDigit(*str))
+ return false;
+ pat++;
+ str++;
+ break;
+
default:
if ((!ignoreCase && *pat != *str) ||
(ignoreCase && tolower(*pat) != tolower(*str))) {
diff --git a/common/str.h b/common/str.h
index a30dae3513..1b41c481c7 100644
--- a/common/str.h
+++ b/common/str.h
@@ -158,6 +158,7 @@ public:
* Token meaning:
* "*": any character, any amount of times.
* "?": any character, only once.
+ * "#": any decimal digit, only once.
*
* Example strings/patterns:
* String: monkey.s01 Pattern: monkey.s?? => true
@@ -165,6 +166,8 @@ public:
* String: monkey.s99 Pattern: monkey.s?1 => false
* String: monkey.s101 Pattern: monkey.s* => true
* String: monkey.s99 Pattern: monkey.s*1 => false
+ * String: monkey.s01 Pattern: monkey.s## => true
+ * String: monkey.s01 Pattern: monkey.### => false
*
* @param pat Glob pattern.
* @param ignoreCase Whether to ignore the case when doing pattern match
@@ -330,6 +333,7 @@ String normalizePath(const String &path, const char sep);
* Token meaning:
* "*": any character, any amount of times.
* "?": any character, only once.
+ * "#": any decimal digit, only once.
*
* Example strings/patterns:
* String: monkey.s01 Pattern: monkey.s?? => true
@@ -337,6 +341,8 @@ String normalizePath(const String &path, const char sep);
* String: monkey.s99 Pattern: monkey.s?1 => false
* String: monkey.s101 Pattern: monkey.s* => true
* String: monkey.s99 Pattern: monkey.s*1 => false
+ * String: monkey.s01 Pattern: monkey.s## => true
+ * String: monkey.s01 Pattern: monkey.### => false
*
* @param str Text to be matched against the given pattern.
* @param pat Glob pattern.
diff --git a/test/common/str.h b/test/common/str.h
index adc6a099e4..3ab5d828c1 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -332,6 +332,9 @@ class StringTestSuite : public CxxTest::TestSuite
TS_ASSERT(!Common::matchString("monkey.s99", "monkey.s*1"));
TS_ASSERT(Common::matchString("monkey.s101", "monkey.s*1"));
+ TS_ASSERT(Common::matchString("monkey.s01", "monkey.s##"));
+ TS_ASSERT(!Common::matchString("monkey.s01", "monkey.###"));
+
TS_ASSERT(!Common::String("").matchString("*_"));
TS_ASSERT(Common::String("a").matchString("a***"));
}