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: locales: ignore @cjkwide and @cjksingle just like @cjknarrow
Date: Mon, 24 Apr 2023 20:42:12 +0000 (GMT)	[thread overview]
Message-ID: <20230424204212.3A2BF3858D28@sourceware.org> (raw)

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

commit 48ae24fd8159109077b71d41e528e08b325ded1f
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Mon Apr 24 22:40:00 2023 +0200
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Mon Apr 24 22:41:41 2023 +0200

    Cygwin: locales: ignore @cjkwide and @cjksingle just like @cjknarrow
    
    When the @cjkwide and @cjksingle modifiers have been added, the
    patches missed to add checks for the new modifiers in the Cygwin
    locale code.  Along the same lines, commit c3e7f7609e46 forgot to
    add a test for @cjksingle.
    
    Merge check for cjk* modifiers into a macro set andf use that
    throughout. Fix comments.
    
    Fixes: f92f048528e6f ("Locale modifier @cjkwide to adjust ambiguous-width in non-CJK locales")
    Fixes: c8204b106988f ("Locale modifier "@cjksingle" to enforce single-width CJK width.")
    Fixes: c3e7f7609e46 ("Cygwin: locales: fix behaviour for @cjk* and @euro locales")
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/nlsfuncs.cc | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/winsup/cygwin/nlsfuncs.cc b/winsup/cygwin/nlsfuncs.cc
index b097a6e5fa0a..7d17b1069e39 100644
--- a/winsup/cygwin/nlsfuncs.cc
+++ b/winsup/cygwin/nlsfuncs.cc
@@ -39,6 +39,18 @@ details. */
 
 #define has_modifier(x)	((x)[0] && !strcmp (modifier, (x)))
 
+/* Check for @cjk* modifier.  Try to be as fast as possible */
+#define __is_cjk_modifier(_in, _cmp, _L) ({ \
+	_in[1] == 'c' \
+	&& _in[2] == 'j' \
+	&& _in[3] == 'k'\
+	&& (_cmp (_in + 4, _L##"narrow") == 0 \
+	    || _cmp (_in + 4, _L##"wide") == 0 \
+	    || _cmp (_in + 4, _L##"single") == 0); \
+})
+#define is_cjk_modifier(_in)	__is_cjk_modifier(_in, strcmp, )
+#define w_is_cjk_modifier(_in)	__is_cjk_modifier(_in, wcscmp, L)
+
 /* ResolveLocaleName does not what we want.  It converts anything which
    vaguely resembles a locale into some other locale it supports.  Bad
    examples are: "en-XY" gets converted to "en-US", and worse, "ff-BF" gets
@@ -532,9 +544,8 @@ __set_lc_time_from_win (const char *name,
 	{
 	  *c = '\0';
 	  char *c2 = strchr (c + 1, '@');
-	  /* Ignore @cjknarrow modifier since it's a very personal thing between
-	     Cygwin and newlib... */
-	  if (c2 && strcmp (c2, "@cjknarrow"))
+	  /* Ignore @cjk* modifiers, they are newlib specials. */
+	  if (c2 && !is_cjk_modifier (c2))
 	    memmove (c, c2, strlen (c2) + 1);
 	}
       /* Now search in the alphabetically order lc_era array for the
@@ -1075,9 +1086,8 @@ __set_lc_messages_from_win (const char *name,
 	{
 	  *c = '\0';
 	  c2 = strchr (c + 1, '@');
-	  /* Ignore @cjknarrow modifier since it's a very personal thing between
-	     Cygwin and newlib... */
-	  if (c2 && strcmp (c2, "@cjknarrow"))
+	  /* Ignore @cjk* modifiers, they are newlib specials. */
+	  if (c2 && !is_cjk_modifier (c2))
 	    memmove (c, c2, strlen (c2) + 1);
 	}
       /* Now search in the alphabetically order lc_msg array for the
@@ -1537,11 +1547,9 @@ __set_charset_from_locale (const char *loc, char *charset)
   modifier = strchr (loc, '@');
   if ((c = strchr (locale, '.')))
     stpcpy (c, modifier ?: "");
-  /* Cut out @cjknarrow/@cjkwide modifier, both are newlib specials and
-    don't affect the codeset. */
+  /* Ignore @cjk* modifiers, they are newlib specials. */
   modifier = strchr (locale, '@');
-  if (modifier && (!strcmp (modifier + 1, "cjknarrow")
-		   || !strcmp (modifier + 1, "cjkwide")))
+  if (modifier && is_cjk_modifier (modifier))
     *modifier = '\0';
 
   default_codeset_t srch_dc = { locale, NULL };
@@ -1702,9 +1710,9 @@ __set_locale_from_locale_alias (const char *locale, char *new_locale)
   if (mbstowcs (wlocale, locale, ENCODING_LEN + 1) == (size_t) -1)
     sys_mbstowcs (wlocale, ENCODING_LEN + 1, locale);
   wlocale[ENCODING_LEN] = L'\0';
-  /* Ignore @cjknarrow modifier since it's a very personal thing between
-     Cygwin and newlib... */
-  if ((wc = wcschr (wlocale, L'@')) && !wcscmp (wc + 1, L"cjknarrow"))
+  /* Ignore @cjk* modifiers, they are newlib specials. */
+  wc = wcschr (wlocale, L'@');
+  if (wc && w_is_cjk_modifier (wc))
     *wc = L'\0';
   while (fgets (alias_buf, LOCALE_ALIAS_LINE_LEN + 1, fp))
     {

                 reply	other threads:[~2023-04-24 20:42 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=20230424204212.3A2BF3858D28@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).