bsnes/nall/string/char/match.hpp

62 lines
1.2 KiB
C++
Raw Normal View History

2011-11-17 12:05:35 +00:00
#ifdef NALL_STRING_INTERNAL_HPP
namespace nall {
bool strmatch(const char* s, const char* p) {
const char* cp = nullptr;
const char* mp = nullptr;
2011-11-17 12:05:35 +00:00
while(*s && *p != '*') {
if(*p != '?' && *s != *p) return false;
p++, s++;
}
while(*s) {
if(*p == '*') {
if(!*++p) return true;
mp = p, cp = s + 1;
} else if(*p == '?' || *p == *s) {
p++, s++;
} else {
p = mp, s = cp++;
}
}
while(*p == '*') p++;
return !*p;
}
bool istrmatch(const char* s, const char* p) {
const char* cp = nullptr;
const char* mp = nullptr;
2011-11-17 12:05:35 +00:00
while(*s && *p != '*') {
if(*p != '?' && chrlower(*s) != chrlower(*p)) return false;
p++, s++;
}
while(*s) {
if(*p == '*') {
if(!*++p) return true;
mp = p, cp = s + 1;
} else if(*p == '?' || chrlower(*p) == chrlower(*s)) {
p++, s++;
} else {
p = mp, s = cp++;
}
}
while(*p == '*') p++;
return !*p;
}
bool tokenize(const char* s, const char* p) {
2011-11-17 12:05:35 +00:00
while(*s) {
if(*p == '*') {
while(*s) if(tokenize(s++, p + 1)) return true;
return !*++p;
}
if(*s++ != *p++) return false;
}
while(*p == '*') p++;
return !*p;
}
}
#endif