public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/main] Cygwin: fnmatch: handle named character classes
Date: Tue, 14 Feb 2023 19:29:22 +0000 (GMT)	[thread overview]
Message-ID: <20230214192922.D44C23858D33@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7faa6465531637d76e3c0733a4d2608bf7b3a54a

commit 7faa6465531637d76e3c0733a4d2608bf7b3a54a
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Tue Feb 14 20:22:54 2023 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Tue Feb 14 20:22:54 2023 +0100

    Cygwin: fnmatch: handle named character classes
    
    Handle [:<character-class>:] expressions in range brackets.
    
    TODO: Collating symbols [.<collsym>'.] and Equivalence class
    expressions [=<equiv-class>=] are recognized but skipped as if
    they are not present at all.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 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 06732426b9c4..9829904f0812 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);

                 reply	other threads:[~2023-02-14 19:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230214192922.D44C23858D33@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).