strlike function checks if a string matches some wild-card like *.dll, *.d??, *.*
strilike is just a case-insensitive analogue
* – any number of any letters
? – exactly one unknown letter

bool
strlike (char* str, char* mask)
{
if (!(str && mask)) {
return false;
}
while (*mask) {
if (*mask == '*') {
while (*mask == '*') {
mask++;
}
if (*mask == '') {
return true;
}
while (*str) {
if (strlike(str, mask)) {
return true;
}
str++;
}
return false;
} else if (*mask == *str || (*mask == '?' && *str != '')) {
str++;
mask++;
} else {
return false;
}
}
return *str == '';
}

bool
strilike (char* str, char* mask)
{
if (!(str && mask)) {
return false;
}
while (*mask) {
if (*mask == '*') {
while (*mask == '*') {
mask++;
}
if (*mask == '') {
return true;
}
while (*str) {
if (strilike(str, mask)) {
return true;
}
str++;
}
return false;
} else if (tolower(*mask) == tolower(*str) || (*mask == '?' && *str != '')) {
str++;
mask++;
} else {
return false;
}
}
return *str == '';
}
Advertisements