return pat[0];
}
-static int match_bracket(const char *p, int k)
+static int casefold(int k)
+{
+ int c = towupper(k);
+ return c == k ? towlower(k) : c;
+}
+
+static int match_bracket(const char *p, int k, int kfold)
{
wchar_t wc;
int inv = 0;
wchar_t wc2;
int l = mbtowc(&wc2, p+1, 4);
if (l < 0) return 0;
- if (wc<=wc2 && (unsigned)k-wc <= wc2-wc) return !inv;
+ if (wc <= wc2)
+ if ((unsigned)k-wc <= wc2-wc ||
+ (unsigned)kfold-wc <= wc2-wc)
+ return !inv;
p += l-1;
continue;
}
char buf[16];
memcpy(buf, p0, p-1-p0);
buf[p-1-p0] = 0;
- if (iswctype(k, wctype(buf))) return !inv;
+ if (iswctype(k, wctype(buf)) ||
+ iswctype(kfold, wctype(buf)))
+ return !inv;
}
continue;
}
if (l < 0) return 0;
p += l-1;
}
- if (wc==k) return !inv;
+ if (wc==k || wc==kfold) return !inv;
}
return inv;
}
const char *p, *ptail, *endpat;
const char *s, *stail, *endstr;
size_t pinc, sinc, tailcnt=0;
- int c, k;
+ int c, k, kfold;
if (flags & FNM_PERIOD) {
if (*str == '.' && *pat != '.')
return (c==END) ? 0 : FNM_NOMATCH;
str += sinc;
n -= sinc;
+ kfold = flags & FNM_CASEFOLD ? casefold(k) : k;
if (c == BRACKET) {
- if (!match_bracket(pat, k))
+ if (!match_bracket(pat, k, kfold))
return FNM_NOMATCH;
- } else if (c != QUESTION && k != c) {
+ } else if (c != QUESTION && k != c && kfold != c) {
return FNM_NOMATCH;
}
pat+=pinc;
break;
}
s += sinc;
+ kfold = flags & FNM_CASEFOLD ? casefold(k) : k;
if (c == BRACKET) {
- if (!match_bracket(p-pinc, k))
+ if (!match_bracket(p-pinc, k, kfold))
return FNM_NOMATCH;
- } else if (c != QUESTION && k != c) {
+ } else if (c != QUESTION && k != c && kfold != c) {
return FNM_NOMATCH;
}
}
k = str_next(s, endstr-s, &sinc);
if (!k)
return FNM_NOMATCH;
+ kfold = flags & FNM_CASEFOLD ? casefold(k) : k;
if (c == BRACKET) {
- if (!match_bracket(p-pinc, k))
+ if (!match_bracket(p-pinc, k, kfold))
break;
- } else if (c != QUESTION && k != c) {
+ } else if (c != QUESTION && k != c && kfold != c) {
break;
}
s += sinc;