#include <iostream>
#include <cctype>
bool wildcardMatch(const char* p, const char* s) {
while (*p != '\0') {
if (*p == '*') {
if (wildcardMatch(p + 1, s)) {
return true;
}
} else if (*p == '?' || tolower(*p) == tolower(*s)) {
++p;
} else {
return false;
}
++s;
}
return (*s == '\0');
}
void test(const char* x, const char* s, bool expect) {
bool result = wildcardMatch(x, s);
std::cout << (result == expect ? " ok : " : "NOT OK : ")
<< s << " matches " << x << " = " << (result ? "yes" : "no")
<< std::endl;
}
int main(int argc, const char* argv[]) {
test("", "", true);
test("", "ab", false);
test("abc", "ab", false);
test("abc", "abc", true);
test("abc", "abcd", false);
test("abc", "abd", false);
test("abc*", "abc", true);
test("abc*", "ab", false);
test("abc*", "abcd", true);
test("abc*", "abcde", true);
test("abc*d*", "abcd", true);
test("abc*d*", "abcxxdyy", true);
test("abc?d*", "abcxxdyy", false);
test("abc?d*", "abcdyy", false);
test("abc?d*", "abcxdyy", true);
return 0;
}