diff options
author | sluicebox | 2019-02-21 16:36:01 -0800 |
---|---|---|
committer | Filippos Karapetis | 2019-03-03 22:44:29 +0200 |
commit | 85333d805036f423114ce811d701b21d2509ec52 (patch) | |
tree | 3811561106b970bee11c273f5c9df849da0515aa /common | |
parent | a3873e7e4bb9022382b97ae9b916aa957f240bdb (diff) | |
download | scummvm-rg350-85333d805036f423114ce811d701b21d2509ec52.tar.gz scummvm-rg350-85333d805036f423114ce811d701b21d2509ec52.tar.bz2 scummvm-rg350-85333d805036f423114ce811d701b21d2509ec52.zip |
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.
Diffstat (limited to 'common')
-rw-r--r-- | common/str.cpp | 25 | ||||
-rw-r--r-- | common/str.h | 1 |
2 files changed, 21 insertions, 5 deletions
diff --git a/common/str.cpp b/common/str.cpp index 8ed652f847..24341ddc44 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -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 == '\\'); } } diff --git a/common/str.h b/common/str.h index 704114b68e..54044cfac0 100644 --- a/common/str.h +++ b/common/str.h @@ -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 |