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: regex: convert wchar_t to wint_t Date: Tue, 14 Feb 2023 12:10:13 +0000 (GMT) [thread overview] Message-ID: <20230214121013.D766C3858417@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=588624da2b0a921c7e72d12d19c2ac3321de0326 commit 588624da2b0a921c7e72d12d19c2ac3321de0326 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Tue Feb 14 13:02:15 2023 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Tue Feb 14 13:02:15 2023 +0100 Cygwin: regex: convert wchar_t to wint_t - call mbrtowi instead of mbrtowc - drop Cygwin-only surrogate handling from wgetnext and xmbrtowc since it's encapsulated in mbrtowi. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/regex/regcomp.c | 25 +++++-------------------- winsup/cygwin/regex/regexec.c | 22 +++------------------- 2 files changed, 8 insertions(+), 39 deletions(-) diff --git a/winsup/cygwin/regex/regcomp.c b/winsup/cygwin/regex/regcomp.c index a377e56fac22..aef104c1ea45 100644 --- a/winsup/cygwin/regex/regcomp.c +++ b/winsup/cygwin/regex/regcomp.c @@ -921,7 +921,7 @@ p_b_coll_elem(struct parse *p, struct cname *cp; int len; mbstate_t mbs; - wchar_t wc; + wint_t wc; size_t clen; while (MORE() && !SEETWO(endc, ']')) @@ -935,7 +935,7 @@ p_b_coll_elem(struct parse *p, if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0') return(cp->code); /* known name */ memset(&mbs, 0, sizeof(mbs)); - if ((clen = mbrtowc(&wc, sp, len, &mbs)) == len) + if ((clen = mbrtowi(&wc, sp, len, &mbs)) == len) return (wc); /* single character */ else if (clen == (size_t)-1 || clen == (size_t)-2) SETERROR(REG_ILLSEQ); @@ -1119,8 +1119,7 @@ static wint_t wgetnext(struct parse *p) { mbstate_t mbs; - wchar_t wc; - wint_t ret; + wint_t wc; size_t n; #ifdef __CYGWIN__ @@ -1136,29 +1135,15 @@ wgetnext(struct parse *p) return (wint_t) (unsigned char) *p->next++; #endif memset(&mbs, 0, sizeof(mbs)); - n = mbrtowc(&wc, p->next, p->end - p->next, &mbs); + n = mbrtowi(&wc, p->next, p->end - p->next, &mbs); if (n == (size_t)-1 || n == (size_t)-2) { SETERROR(REG_ILLSEQ); return (0); } - ret = wc; if (n == 0) n = 1; - else if (sizeof (wchar_t) == 2 && wc >= 0xd800 && wc <= 0xdbff) { - /* UTF-16 surrogate pair. Fetch second half and - compute UTF-32 value */ - size_t n2 = mbrtowc(&wc, p->next + n, - p->end - p->next - n, &mbs); - if (n2 == 0 || n2 == (size_t)-1 || n2 == (size_t)-2) { - SETERROR(REG_ILLSEQ); - return (0); - } - ret = (((ret & 0x3ff) << 10) | (wc & 0x3ff)) - + 0x10000; - n += n2; - } p->next += n; - return (ret); + return (wc); } static size_t diff --git a/winsup/cygwin/regex/regexec.c b/winsup/cygwin/regex/regexec.c index c400578b898d..94e95e65abcd 100644 --- a/winsup/cygwin/regex/regexec.c +++ b/winsup/cygwin/regex/regexec.c @@ -68,9 +68,9 @@ static __inline size_t xmbrtowc(wint_t *wi, const char *s, size_t n, mbstate_t *mbs, wint_t dummy) { size_t nr; - wchar_t wc; + wint_t wc; - nr = mbrtowc(&wc, s, n, mbs); + nr = mbrtowi(&wc, s, n, mbs); if (wi != NULL) *wi = wc; if (nr == 0) @@ -80,24 +80,8 @@ xmbrtowc(wint_t *wi, const char *s, size_t n, mbstate_t *mbs, wint_t dummy) if (wi != NULL) *wi = dummy; return (1); - } else { - if (sizeof (wchar_t) == 2 && wc >= 0xd800 && wc <= 0xdbff) { - /* UTF-16 surrogate pair. Fetch second half and - compute UTF-32 value */ - size_t n2 = mbrtowc(&wc, s + nr, n - nr, mbs); - if (n2 == 0 || n2 == (size_t)-1 || n2 == (size_t)-2) { - memset(mbs, 0, sizeof(*mbs)); - if (wi != NULL) - *wi = dummy; - return (1); - } - if (wi != NULL) - *wi = (((*wi & 0x3ff) << 10) | (wc & 0x3ff)) - + 0x10000; - nr += n2; - } + } else return (nr); - } } static __inline size_t
reply other threads:[~2023-02-14 12:10 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=20230214121013.D766C3858417@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: linkBe 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).