Сообщение Re: filesystem поиск по маске от 18.10.2018 7:52
Изменено 18.10.2018 13:56 PavelCH
Re: filesystem поиск по маске
Вот еще одна примитивная реализация:
// text - это исходный текст
// s - это шаблон. Понимает '*' и '?'
static bool match_pattern(const char* text, const char* s) {
const char* s2 = s + strlen(s);
while(true) {
const char* d = text;
while(s < s2) {
if(*d == 0)
return false;
unsigned char c = *s;
if(c == '?') {
s++;
d++;
} else if(c == '*') {
s++;
if(s == s2)
return true;
while(*d) {
if(*d == *s)
break;
d++;
}
} else {
if(*d++ != *s++)
return false;
}
}
return true;
}
}
Re: filesystem поиск по маске
Вот еще одна примитивная реализация:
// text - это исходный текст
// s - это шаблон. Понимает '*' и '?'
static bool match_pattern(const char* text, const char* s) {
const char* s2 = s + strlen(s);
const char* d = text;
while(s < s2) {
if(*d == 0)
return false;
unsigned char c = *s;
if(c == '?') {
s++;
d++;
} else if(c == '*') {
s++;
if(s == s2)
return true;
while(*d) {
if(*d == *s)
break;
d++;
}
} else {
if(*d++ != *s++)
return false;
}
}
return true;
}