From 7faa6465531637d76e3c0733a4d2608bf7b3a54a Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 14 Feb 2023 20:22:54 +0100 Subject: [PATCH] Cygwin: fnmatch: handle named character classes Handle [::] expressions in range brackets. TODO: Collating symbols [.'.] and Equivalence class expressions [==] are recognized but skipped as if they are not present at all. Signed-off-by: Corinna Vinschen --- winsup/cygwin/libc/fnmatch.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/winsup/cygwin/libc/fnmatch.c b/winsup/cygwin/libc/fnmatch.c index 06732426b..9829904f0 100644 --- a/winsup/cygwin/libc/fnmatch.c +++ b/winsup/cygwin/libc/fnmatch.c @@ -274,6 +274,29 @@ rangematch(const char *pattern, wint_t test, int flags, char **newp, return (RANGE_NOMATCH); } else if (*pattern == '\\' && !(flags & FNM_NOESCAPE)) pattern++; + if (*pattern == '[' && (pattern[1] == ':' || pattern[1] == '.' + || pattern[1] == '=')) { + const char ctype = *++pattern; + const char *class_p = ++pattern; + + while (*pattern + && (*pattern != ctype || pattern[1] != ']')) + ++pattern; + if (!*pattern) + return (RANGE_ERROR); + if (ctype == ':') { + size_t clen = pattern - class_p; + char class[clen + 1]; + + *stpncpy (class, class_p, clen) = '\0'; + if (iswctype (test, wctype (class))) + ok = 1; + } + pattern += 2; + /* TODO: [. and [= are just ignored for now */ + continue; + + } pclen = mbrtowi(&c, pattern, MB_LEN_MAX, patmbs); if (pclen == (size_t)-1 || pclen == (size_t)-2) return (RANGE_NOMATCH);