]> Savannah Git Hosting - gnulib.git/commitdiff
Fix mbscasestr test failure on native Windows with MSVC.
authorBruno Haible <bruno@clisp.org>
Sun, 1 Sep 2024 11:09:59 +0000 (13:09 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 1 Sep 2024 11:09:59 +0000 (13:09 +0200)
* lib/c32to-impl.h (FUNC): On native Windows, ignore the system's
towlower/towupper function entirely.
* tests/test-c32tolower.c (main): On native Windows, reenable test that
previously failed.
* tests/test-c32toupper.c (main): Likewise. Disable two other tests on
native Windows.
* doc/posix-functions/towlower.texi: Mention bug in the native Windows
UTF-8 locale.
* doc/posix-functions/towupper.texi: Likewise.

ChangeLog
doc/posix-functions/towlower.texi
doc/posix-functions/towupper.texi
lib/c32to-impl.h
tests/test-c32tolower.c
tests/test-c32toupper.c

index 2a9d575f42bbfd03aff821f533f773786effa4ad..25826b49c26384167b16231a81db8085986d1a39 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-09-01  Bruno Haible  <bruno@clisp.org>
+
+       Fix mbscasestr test failure on native Windows with MSVC.
+       * lib/c32to-impl.h (FUNC): On native Windows, ignore the system's
+       towlower/towupper function entirely.
+       * tests/test-c32tolower.c (main): On native Windows, reenable test that
+       previously failed.
+       * tests/test-c32toupper.c (main): Likewise. Disable two other tests on
+       native Windows.
+       * doc/posix-functions/towlower.texi: Mention bug in the native Windows
+       UTF-8 locale.
+       * doc/posix-functions/towupper.texi: Likewise.
+
 2024-09-01  Bruno Haible  <bruno@clisp.org>
 
        Fix quoting of $LOCALE_EN_UTF8 (regression yesterday).
index 3ac7336ed0592b798496c1026f3ad4cae0029be3..500c8fff1c948eef483b24598d0eda3391846a41 100644 (file)
@@ -27,6 +27,9 @@ However, the Gnulib function @code{c32tolower}, provided by Gnulib module
 @code{c32tolower}, operates on 32-bit wide characters and therefore does not
 have this limitation.
 @item
+On native Windows, in an UTF-8 locale, this function does not even do
+the simple expected mappings, such as from 0x00C9 to 0x00E9.
+@item
 This function returns wrong values even for the ASCII characters
 in a zh_CN.GB18030 locale on some platforms:
 @c https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=57339
index 4ce05b946e3c59665d4f09d72d821aeaeef2cc94..860b7ae4386f5114bdb24a481ab65952a18f568f 100644 (file)
@@ -27,6 +27,9 @@ However, the Gnulib function @code{c32toupper}, provided by Gnulib module
 @code{c32toupper}, operates on 32-bit wide characters and therefore does not
 have this limitation.
 @item
+On native Windows, in an UTF-8 locale, this function does not even do
+the simple expected mappings, such as from 0x00E9 to 0x00C9.
+@item
 This function returns wrong values even for the ASCII characters
 in a zh_CN.GB18030 locale on some platforms:
 @c https://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=57339
index 32039c612d0c4cbab356db82cf1451470ce94435..2299ab75ba1fe4f26a3564fbb062e757b0557c13 100644 (file)
@@ -73,11 +73,22 @@ FUNC (wint_t wc)
   /* The wchar_t encoding is UTF-16.
      The char32_t encoding is UCS-4.  */
 
+# if defined _WIN32 && !defined __CYGWIN__
+  /* On native Windows, in the UTF-8 locale, towlower and towupper are
+     lacking (at least) the mappings for ISO-8859-1 characters, such as
+     0x00C9 <-> 0x00E9.  Since it is expensive to test whether the locale
+     encoding is UTF-8, ignore the system's WCHAR_FUNC altogether.  */
+  if (wc != WEOF)
+    return UCS_FUNC (wc);
+  else
+    return wc;
+# else
   if (wc == WEOF || wc == (wchar_t) wc)
     /* wc is in the range for the tow* functions.  */
     return WCHAR_FUNC (wc);
   else
     return UCS_FUNC (wc);
+# endif
 
 #else /* macOS, FreeBSD, NetBSD, OpenBSD, HP-UX, Solaris, Minix, Android */
   /* char32_t and wchar_t are equivalent.  */
index eb956b50092f1dc5617c453e2fcafcce6255f3f9..072338bde1f9aca0cd67fe05f9546f351822263b 100644 (file)
@@ -255,12 +255,10 @@ main (int argc, char *argv[])
           mb = for_character ("\302\265", 2);
           ASSERT (mb.nbytes == 2);
           ASSERT (memcmp (mb.buf, "\302\265", 2) == 0);
-        #if !(defined _WIN32 && !defined __CYGWIN__)
           /* U+00C9 LATIN CAPITAL LETTER E WITH ACUTE */
           mb = for_character ("\303\211", 2);
           ASSERT (mb.nbytes == 2);
           ASSERT (memcmp (mb.buf, "\303\251", 2) == 0);
-        #endif
           /* U+00DF LATIN SMALL LETTER SHARP S */
           mb = for_character ("\303\237", 2);
           ASSERT (mb.nbytes == 2);
index 18c3ffddb590aa607ba7962d4eef20c623d4d0e9..eb9668afff17ad7868c995fd383c022ea2a5eec7 100644 (file)
@@ -163,7 +163,7 @@ main (int argc, char *argv[])
           mb = for_character ("\262", 1);
           ASSERT (mb.nbytes == 1);
           ASSERT (memcmp (mb.buf, "\262", 1) == 0);
-        #if !(defined __GLIBC__ || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __NetBSD__ || defined __sun || defined __CYGWIN__)
+        #if !(defined __GLIBC__ || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __NetBSD__ || defined __sun || defined __CYGWIN__ || (defined _WIN32 && !defined __CYGWIN__))
           /* U+00B5 MICRO SIGN */
           mb = for_character ("\265", 1);
           ASSERT (mb.nbytes == 1);
@@ -259,7 +259,7 @@ main (int argc, char *argv[])
           mb = for_character ("\302\262", 2);
           ASSERT (mb.nbytes == 2);
           ASSERT (memcmp (mb.buf, "\302\262", 2) == 0);
-        #if !(defined __GLIBC__ || defined MUSL_LIBC || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __OpenBSD__ || defined _AIX || defined __sun || defined __CYGWIN__ || defined __ANDROID__)
+        #if !(defined __GLIBC__ || defined MUSL_LIBC || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __OpenBSD__ || defined _AIX || defined __sun || defined __CYGWIN__ || (defined _WIN32 && !defined __CYGWIN__) || defined __ANDROID__)
           /* U+00B5 MICRO SIGN */
           mb = for_character ("\302\265", 2);
           ASSERT (mb.nbytes == 2);
@@ -275,7 +275,6 @@ main (int argc, char *argv[])
           ASSERT (mb.nbytes == 2);
           ASSERT (memcmp (mb.buf, "\303\237", 2) == 0);
         #endif
-        #if !(defined _WIN32 && !defined __CYGWIN__)
           /* U+00E9 LATIN SMALL LETTER E WITH ACUTE */
           mb = for_character ("\303\251", 2);
           ASSERT (mb.nbytes == 2);
@@ -284,7 +283,6 @@ main (int argc, char *argv[])
           mb = for_character ("\303\277", 2);
           ASSERT (mb.nbytes == 2);
           ASSERT (memcmp (mb.buf, "\305\270", 2) == 0);
-        #endif
           /* U+0141 LATIN CAPITAL LETTER L WITH STROKE */
           mb = for_character ("\305\201", 2);
           ASSERT (mb.nbytes == 2);