aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/str.cpp5
-rw-r--r--test/common/str.h8
2 files changed, 13 insertions, 0 deletions
diff --git a/common/str.cpp b/common/str.cpp
index b2c9a7cdbf..a415e376c9 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -605,13 +605,18 @@ bool matchString(const char *str, const char *pat) {
for (;;) {
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)
diff --git a/test/common/str.h b/test/common/str.h
index 921c4614f5..a94ec3227f 100644
--- a/test/common/str.h
+++ b/test/common/str.h
@@ -191,6 +191,14 @@ class StringTestSuite : public CxxTest::TestSuite
}
void test_matchString(void) {
+ TS_ASSERT( Common::matchString("", "*"));
+ TS_ASSERT( Common::matchString("a", "*"));
+ TS_ASSERT( Common::matchString("monkey.s01", "*"));
+
+ TS_ASSERT(!Common::matchString("", "?"));
+ TS_ASSERT( Common::matchString("a", "?"));
+ TS_ASSERT(!Common::matchString("monkey.s01", "?"));
+
TS_ASSERT( Common::matchString("monkey.s01", "monkey.s??"));
TS_ASSERT( Common::matchString("monkey.s99", "monkey.s??"));
TS_ASSERT(!Common::matchString("monkey.s101", "monkey.s??"));