]> Savannah Git Hosting - gnulib.git/commitdiff
mbmemcasecoll: Overcome wchar_t limitations.
authorBruno Haible <bruno@clisp.org>
Sun, 2 Jul 2023 13:44:19 +0000 (15:44 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 2 Jul 2023 13:44:19 +0000 (15:44 +0200)
* lib/mbmemcasecoll.c: Include <uchar.h> instead of <wctype.h>.
(apply_c32tolower): Renamed from apply_towlower. Use mbrtoc32 instead of
mbrtowc. Use c32tolower instead of towlower. Use c32rtomb instead of
wcrtomb.
* modules/mbmemcasecoll (Depends-on): Remove mbrtowc, wcrtomb. Add
uchar, mbrtoc32, c32rtomb, c32tolower.
(Link): Add $(LIBUNISTRING) $(LIBC32CONV).
* modules/mbmemcasecoll-tests (Makefile.am): Link test-mbmemcasecoll
with $(LIBUNISTRING) $(LIBC32CONV).

ChangeLog
lib/mbmemcasecoll.c
modules/mbmemcasecoll
modules/mbmemcasecoll-tests

index 898ebbb4c5cd2007d0880df9e1670549c205be56..187a1abbda30a349d09f4124710b0f7a793a29a1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2023-07-02  Bruno Haible  <bruno@clisp.org>
+
+       mbmemcasecoll: Overcome wchar_t limitations.
+       * lib/mbmemcasecoll.c: Include <uchar.h> instead of <wctype.h>.
+       (apply_c32tolower): Renamed from apply_towlower. Use mbrtoc32 instead of
+       mbrtowc. Use c32tolower instead of towlower. Use c32rtomb instead of
+       wcrtomb.
+       * modules/mbmemcasecoll (Depends-on): Remove mbrtowc, wcrtomb. Add
+       uchar, mbrtoc32, c32rtomb, c32tolower.
+       (Link): Add $(LIBUNISTRING) $(LIBC32CONV).
+       * modules/mbmemcasecoll-tests (Makefile.am): Link test-mbmemcasecoll
+       with $(LIBUNISTRING) $(LIBC32CONV).
+
 2023-07-02  Bruno Haible  <bruno@clisp.org>
 
        mbswidth: Overcome wchar_t limitations.
index 6f4acb7e777e763d8404c79cd8e4a2d2437dc0a8..de7390f6d1c34c88d13fb8b4a69fd1a151d698b8 100644 (file)
 /* Get tolower().  */
 #include <ctype.h>
 
-/* Get mbstate_t, mbrtowc(), wcrtomb().  */
+/* Get mbstate_t.  */
 #include <wchar.h>
 
-/* Get towlower().  */
-#include <wctype.h>
+/* Get char32_t, mbrtoc32(), c32rtomb(), c32tolower().  */
+#include <uchar.h>
 
 #include "malloca.h"
 #include "memcmp2.h"
 
 #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
 
-/* Apply towlower() to the multibyte character sequence in INBUF, storing the
+/* Apply c32tolower() to the multibyte character sequence in INBUF, storing the
    result as a multibyte character sequence in OUTBUF.  */
 static size_t
-apply_towlower (const char *inbuf, size_t inbufsize,
-                char *outbuf, size_t outbufsize)
+apply_c32tolower (const char *inbuf, size_t inbufsize,
+                  char *outbuf, size_t outbufsize)
 {
   char *outbuf_orig = outbuf;
   size_t remaining;
@@ -51,12 +51,12 @@ apply_towlower (const char *inbuf, size_t inbufsize,
   remaining = inbufsize;
   while (remaining > 0)
     {
-      wchar_t wc1;
+      char32_t wc1;
       size_t n1;
       mbstate_t state;
 
       memset (&state, '\0', sizeof (mbstate_t));
-      n1 = mbrtowc (&wc1, inbuf, remaining, &state);
+      n1 = mbrtoc32 (&wc1, inbuf, remaining, &state);
       if (n1 == (size_t)(-2))
         break;
       if (n1 != (size_t)(-1))
@@ -65,14 +65,16 @@ apply_towlower (const char *inbuf, size_t inbufsize,
 
           if (n1 == 0) /* NUL character? */
             n1 = 1;
+          else if (n1 == (size_t)(-3))
+            n1 = 0;
 
-          wc2 = towlower (wc1);
+          wc2 = c32tolower (wc1);
           if (wc2 != wc1)
             {
               size_t n2;
 
               memset (&state, '\0', sizeof (mbstate_t));
-              n2 = wcrtomb (outbuf, wc2, &state);
+              n2 = c32rtomb (outbuf, wc2, &state);
               if (n2 != (size_t)(-1))
                 {
                   /* Store the translated multibyte character.  */
@@ -162,8 +164,8 @@ mbmemcasecoll (const char *s1, size_t s1len, const char *s2, size_t s2len,
   /* Case-fold the two argument strings.  */
   if (MB_CUR_MAX > 1)
     {
-      t1len = apply_towlower (s1, s1len, t1, t1len);
-      t2len = apply_towlower (s2, s2len, t2, t2len);
+      t1len = apply_c32tolower (s1, s1len, t1, t1len);
+      t2len = apply_c32tolower (s2, s2len, t2, t2len);
     }
   else
     {
index 7401d310c9f99cadc1e189025e93df10d1f610f8..ee52717f3e60b24fa41375644b3a7d5898212a87 100644 (file)
@@ -8,12 +8,14 @@ lib/mbmemcasecoll.c
 
 Depends-on:
 stdbool
+wchar
+uchar
 malloca
-mbrtowc
-wcrtomb
+mbrtoc32
+c32rtomb
+c32tolower
 memcmp2
 memcoll
-wchar
 
 configure.ac:
 
@@ -24,7 +26,9 @@ Include:
 "mbmemcasecoll.h"
 
 Link:
+$(LTLIBUNISTRING) when linking with libtool, $(LIBUNISTRING) otherwise
 $(MBRTOWC_LIB)
+$(LTLIBC32CONV) when linking with libtool, $(LIBC32CONV) otherwise
 
 License:
 GPL
index 8fa28058720e56953dee0a96c9b510c2c8ec21d2..28a982e4e627e54938a1f3269dbee45c2f957b30 100644 (file)
@@ -25,4 +25,4 @@ TESTS_ENVIRONMENT += \
   LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \
   LOCALE_TR_UTF8='@LOCALE_TR_UTF8@'
 check_PROGRAMS += test-mbmemcasecoll
-test_mbmemcasecoll_LDADD = $(LDADD) $(SETLOCALE_LIB) $(MBRTOWC_LIB)
+test_mbmemcasecoll_LDADD = $(LDADD) $(SETLOCALE_LIB) $(LIBUNISTRING) $(MBRTOWC_LIB) $(LIBC32CONV)