]> 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>
Tue, 17 Sep 2024 13:51:37 +0000 (15:51 +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 90d02b0e3bc7cefd051d2e958b61b12d244c762c..35592dd9534ed51019eb1ca4424ab770de9518db 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-08-31  Bruno Haible  <bruno@clisp.org>
 
        tests: Avoid some test failures on Android.
index b6c51a4571201a8d45bb832d61d35bfcf464e7f3..8ab444d487dec574e2023d14d30866f4f5c01345 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 bd29eec9ad0acb54f1b3e4c2d016df03f4707779..3b6d2ed82ffbc5cabc2dbb08d85d7c920b14a28f 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 681191b4adcc7adebae837aa9f8a2ed0cf73e93e..8d0d9183c03da332a336e2bae9b035fa2f989fb2 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 e81c86539aff6930ae08db036e276d568d09b12d..e6b3b1bbf1cd9f43b7a6560e420571edbe30192c 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);