mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-21 03:31:40 +00:00
COMMON: Allow '\#' to match '#' in matchString
matchString patterns couldn't be used to find files with the # character as it was only treated as a digit wildcard. SCI expected that to work as it looks for files that start with the # character.
This commit is contained in:
parent
a3873e7e4b
commit
85333d8050
@ -884,6 +884,7 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod
|
||||
|
||||
const char *p = nullptr;
|
||||
const char *q = nullptr;
|
||||
bool escaped = false;
|
||||
|
||||
for (;;) {
|
||||
if (pathMode && *str == '/') {
|
||||
@ -893,6 +894,7 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod
|
||||
return false;
|
||||
}
|
||||
|
||||
const char curPat = *pat;
|
||||
switch (*pat) {
|
||||
case '*':
|
||||
if (*str) {
|
||||
@ -912,12 +914,23 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod
|
||||
return true;
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
if (!escaped) {
|
||||
pat++;
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
|
||||
case '#':
|
||||
if (!isDigit(*str))
|
||||
return false;
|
||||
pat++;
|
||||
str++;
|
||||
break;
|
||||
// treat # as a wildcard for digits unless escaped
|
||||
if (!escaped) {
|
||||
if (!isDigit(*str))
|
||||
return false;
|
||||
pat++;
|
||||
str++;
|
||||
break;
|
||||
}
|
||||
// fallthrough
|
||||
|
||||
default:
|
||||
if ((!ignoreCase && *pat != *str) ||
|
||||
@ -940,6 +953,8 @@ bool matchString(const char *str, const char *pat, bool ignoreCase, bool pathMod
|
||||
pat++;
|
||||
str++;
|
||||
}
|
||||
|
||||
escaped = !escaped && (curPat == '\\');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,6 +179,7 @@ public:
|
||||
* "*": any character, any amount of times.
|
||||
* "?": any character, only once.
|
||||
* "#": any decimal digit, only once.
|
||||
* "\#": #, only once.
|
||||
*
|
||||
* Example strings/patterns:
|
||||
* String: monkey.s01 Pattern: monkey.s?? => true
|
||||
|
@ -335,6 +335,10 @@ class StringTestSuite : public CxxTest::TestSuite
|
||||
TS_ASSERT(Common::matchString("monkey.s01", "monkey.s##"));
|
||||
TS_ASSERT(!Common::matchString("monkey.s01", "monkey.###"));
|
||||
|
||||
TS_ASSERT(Common::matchString("monkey.s0#", "monkey.s0\\#"));
|
||||
TS_ASSERT(!Common::matchString("monkey.s0#", "monkey.s0#"));
|
||||
TS_ASSERT(!Common::matchString("monkey.s01", "monkey.s0\\#"));
|
||||
|
||||
TS_ASSERT(!Common::String("").matchString("*_"));
|
||||
TS_ASSERT(Common::String("a").matchString("a***"));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user