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
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 == '\0') { return true; } while (*str) { if (strlike(str, mask)) { return true; } str++; } return false; } else if (*mask == *str || (*mask == '?' && *str != '\0')) { str++; mask++; } else { return false; } } return *str == '\0'; } bool strilike (char* str, char* mask) { if (!(str && mask)) { return false; } while (*mask) { if (*mask == '*') { while (*mask == '*') { mask++; } if (*mask == '\0') { return true; } while (*str) { if (strilike(str, mask)) { return true; } str++; } return false; } else if (tolower(*mask) == tolower(*str) || (*mask == '?' && *str != '\0')) { str++; mask++; } else { return false; } } return *str == '\0'; }
Немає коментарів:
Дописати коментар