]> Savannah Git Hosting - gnulib.git/commitdiff
Remaining support for GNULIB_MCEL_PREFER
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 26 Sep 2023 22:49:02 +0000 (15:49 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 26 Sep 2023 22:50:31 +0000 (15:50 -0700)
Support mcel API in remaining modules where this might matter,
for apps that prefer it.
* lib/mbmemcasecmp.c, lib/mbscspn.c, lib/mbsncasecmp.c, lib/mbsnlen.c:
* lib/mbspbrk.c, lib/mbspcasecmp.c, lib/mbssep.c, lib/mbsspn.c:
* lib/regex-quote.c:
Include mcel.h instead of mbiterf.h or mbuiterf.h,
if GNULIB_MCEL_PREFER.
* lib/mbmemcasecmp.c (mbmemcasecmp), lib/mbscspn.c (mbscspn):
* lib/mbsncasecmp.c (mbsncasecmp), lib/mbsnlen.c (mbsnlen):
* lib/mbspbrk.c (mbspbrk), lib/mbspcasecmp.c (mbspcasecmp):
* lib/mbssep.c (mbssep), lib/mbsspn.c (mbsspn):
* lib/regex-quote.c (regex_quote_length, regex_quote_copy):
Use mcel API, if GNULIB_MCEL_PREFER.
* lib/mbscspn.c, lib/mbspbrk.c, lib/mbspcasecmp.c, lib/mbsspn.c:
Include stdlib.h, for MB_CUR_MAX.
* modules/mbmemcasecmp, modules/mbsncasecmp, modules/mbspcasecmp:
Depend on c32tolower.
* modules/regex-quote: Depend on mempcpy.

14 files changed:
ChangeLog
lib/mbmemcasecmp.c
lib/mbscspn.c
lib/mbsncasecmp.c
lib/mbsnlen.c
lib/mbspbrk.c
lib/mbspcasecmp.c
lib/mbssep.c
lib/mbsspn.c
lib/regex-quote.c
modules/mbmemcasecmp
modules/mbsncasecmp
modules/mbspcasecmp
modules/regex-quote

index 7b7246f2a58446895fd88b31305658afabbfa3ae..d405872dffd113247af2832129e345320f5f4865 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2023-09-26  Paul Eggert  <eggert@cs.ucla.edu>
+
+       Remaining support for GNULIB_MCEL_PREFER
+       Support mcel API in remaining modules where this might matter,
+       for apps that prefer it.
+       * lib/mbmemcasecmp.c, lib/mbscspn.c, lib/mbsncasecmp.c, lib/mbsnlen.c:
+       * lib/mbspbrk.c, lib/mbspcasecmp.c, lib/mbssep.c, lib/mbsspn.c:
+       * lib/regex-quote.c:
+       Include mcel.h instead of mbiterf.h or mbuiterf.h,
+       if GNULIB_MCEL_PREFER.
+       * lib/mbmemcasecmp.c (mbmemcasecmp), lib/mbscspn.c (mbscspn):
+       * lib/mbsncasecmp.c (mbsncasecmp), lib/mbsnlen.c (mbsnlen):
+       * lib/mbspbrk.c (mbspbrk), lib/mbspcasecmp.c (mbspcasecmp):
+       * lib/mbssep.c (mbssep), lib/mbsspn.c (mbsspn):
+       * lib/regex-quote.c (regex_quote_length, regex_quote_copy):
+       Use mcel API, if GNULIB_MCEL_PREFER.
+       * lib/mbscspn.c, lib/mbspbrk.c, lib/mbspcasecmp.c, lib/mbsspn.c:
+       Include stdlib.h, for MB_CUR_MAX.
+       * modules/mbmemcasecmp, modules/mbsncasecmp, modules/mbspcasecmp:
+       Depend on c32tolower.
+       * modules/regex-quote: Depend on mempcpy.
+
 2023-09-25  Paul Eggert  <eggert@cs.ucla.edu>
 
        mbscasestr: support GNULIB_MCEL_PREFER
index 2bf4effa479d693edb5fe5c78e95f323110981b0..0ecc8f34d27e52277f29cc16d2679a7bcb6fdd58 100644 (file)
 #include <limits.h>
 #include <stdlib.h>
 
-#include "mbiterf.h"
+#if GNULIB_MCEL_PREFER
+# include "mcel.h"
+#else
+# include "mbiterf.h"
+#endif
 
 int
 mbmemcasecmp (const char *s1, size_t n1, const char *s2, size_t n2)
@@ -35,14 +39,25 @@ mbmemcasecmp (const char *s1, size_t n1, const char *s2, size_t n2)
 
   const char *iter1 = s1;
   const char *iter2 = s2;
+  const char *s1_end = s1 + n1;
+  const char *s2_end = s2 + n2;
 
   if (MB_CUR_MAX > 1)
     {
-      const char *s1_end = s1 + n1;
+#if GNULIB_MCEL_PREFER
+      while ((iter1 < s1_end) & (iter2 < s2_end))
+        {
+          mcel_t g1 = mcel_scan (iter1, s1_end); iter1 += g1.len;
+          mcel_t g2 = mcel_scan (iter2, s2_end); iter2 += g2.len;
+          int cmp = mcel_tocmp (c32tolower, g1, g2);
+          if (cmp)
+            return cmp;
+        }
+      return (iter1 < s1_end) - (iter2 < s2_end);
+#else
       mbif_state_t state1;
       mbif_init (state1);
 
-      const char *s2_end = s2 + n2;
       mbif_state_t state2;
       mbif_init (state2);
 
@@ -66,12 +81,10 @@ mbmemcasecmp (const char *s1, size_t n1, const char *s2, size_t n2)
         /* s1 terminated before s2.  */
         return -1;
       return 0;
+#endif
     }
   else
     {
-      const char *s1_end = s1 + n1;
-      const char *s2_end = s2 + n2;
-
       while (iter1 < s1_end && iter2 < s2_end)
         {
           unsigned char c1 = *iter1++;
index f67a557f4b15027f3351afbf134faf84a3a9313d..e5af4b464848ced6993ea667d99df4f9cc6af36c 100644 (file)
 /* Specification.  */
 #include <string.h>
 
-#include "mbuiterf.h"
+#include <stdlib.h>
+
+#if GNULIB_MCEL_PREFER
+# include "mcel.h"
+#else
+# include "mbuiterf.h"
+#endif
 
 /* Find the first occurrence in the character string STRING of any character
    in the character string ACCEPT.  Return the number of bytes from the
@@ -40,6 +46,27 @@ mbscspn (const char *string, const char *accept)
   /* General case.  */
   if (MB_CUR_MAX > 1)
     {
+#if GNULIB_MCEL_PREFER
+      mcel_t a, g;
+      size_t i;
+      for (i = 0; string[i]; i += g.len)
+        {
+          g = mcel_scanz (string + i);
+          if (g.len == 1)
+            {
+              if (mbschr (accept, string[i]))
+                return i;
+            }
+          else
+            for (char const *aiter = accept; *aiter; aiter += a.len)
+              {
+                a = mcel_scanz (aiter);
+                if (mcel_cmp (g, a) == 0)
+                  return i;
+              }
+        }
+      return i;
+#else
       mbuif_state_t state;
       const char *iter;
       for (mbuif_init (state), iter = string; mbuif_avail (state, iter); )
@@ -67,6 +94,7 @@ mbscspn (const char *string, const char *accept)
         }
      found:
       return iter - string;
+#endif
     }
   else
     return strcspn (string, accept);
index 8ee1df7d4d25dcdeefcbb58e1fb233ca74676668..d58a18f23bffa815ec6cddf6b0c04a3aa8aa42d7 100644 (file)
 
 #include <ctype.h>
 #include <limits.h>
+#include <stdlib.h>
 
-#include "mbuiterf.h"
+#if GNULIB_MCEL_PREFER
+# include "mcel.h"
+#else
+# include "mbuiterf.h"
+#endif
 
 /* Compare the initial segment of the character string S1 consisting of at most
    N characters with the initial segment of the character string S2 consisting
@@ -47,6 +52,17 @@ mbsncasecmp (const char *s1, const char *s2, size_t n)
      most often already in the very few first characters.  */
   if (MB_CUR_MAX > 1)
     {
+#if GNULIB_MCEL_PREFER
+      while (true)
+        {
+          mcel_t g1 = mcel_scanz (iter1); iter1 += g1.len;
+          mcel_t g2 = mcel_scanz (iter2); iter2 += g2.len;
+          int cmp = mcel_tocmp (c32tolower, g1, g2);
+          n--;
+          if (cmp | !n | !g1.ch)
+            return cmp;
+        }
+#else
       mbuif_state_t state1;
       mbuif_init (state1);
 
@@ -75,6 +91,7 @@ mbsncasecmp (const char *s1, const char *s2, size_t n)
         /* s1 terminated before s2 and n.  */
         return -1;
       return 0;
+#endif
     }
   else
     for (;;)
index ec1dfcaec3e7aff46e4a867b06d0f918217c92d5..c15dd3032eb8973db84143e6992b967e6764d153 100644 (file)
 
 #include <stdlib.h>
 
-#include "mbiterf.h"
+#if GNULIB_MCEL_PREFER
+# include "mcel.h"
+#else
+# include "mbiterf.h"
+#endif
 
 /* Return the number of multibyte characters in the character string starting
    at STRING and ending at STRING + LEN.  */
@@ -34,6 +38,11 @@ mbsnlen (const char *string, size_t len)
       size_t count = 0;
 
       const char *string_end = string + len;
+
+#if GNULIB_MCEL_PREFER
+      for (; *string; string += mcel_scan (string, string_end).len)
+        count++;
+#else
       mbif_state_t state;
       const char *iter;
       for (mbif_init (state), iter = string; mbif_avail (state, iter, string_end); )
@@ -42,6 +51,7 @@ mbsnlen (const char *string, size_t len)
           count++;
           iter += mb_len (cur);
         }
+#endif
 
       return count;
     }
index 9482eb00cb8643f227acabad380530308a75c3da..b1ee02942f45117613374c39471b39e2db1eda67 100644 (file)
 /* Specification.  */
 #include <string.h>
 
-#include "mbuiterf.h"
+#include <stdlib.h>
+
+#if GNULIB_MCEL_PREFER
+# include "mcel.h"
+#else
+# include "mbuiterf.h"
+#endif
 
 /* Find the first occurrence in the character string STRING of any character
    in the character string ACCEPT.  Return the pointer to it, or NULL if none
@@ -36,9 +42,28 @@ mbspbrk (const char *string, const char *accept)
   /* General case.  */
   if (MB_CUR_MAX > 1)
     {
+      char const *iter = string;
+#if GNULIB_MCEL_PREFER
+      mcel_t a, g;
+      for (char const *iter = string; *iter; iter += g.len)
+        {
+          g = mcel_scanz (iter);
+          if (g.len == 1)
+            {
+              if (mbschr (accept, *iter))
+                return (char *) iter;
+            }
+          else
+            for (char const *aiter = accept; *aiter; aiter += a.len)
+              {
+                a = mcel_scanz (aiter);
+                if (mcel_cmp (a, g) == 0)
+                  return (char *) iter;
+              }
+        }
+#else
       mbuif_state_t state;
-      const char *iter;
-      for (mbuif_init (state), iter = string; mbuif_avail (state, iter); )
+      for (mbuif_init (state); mbuif_avail (state, iter); )
         {
           mbchar_t cur = mbuif_next (state, iter);
           if (mb_len (cur) == 1)
@@ -61,6 +86,7 @@ mbspbrk (const char *string, const char *accept)
             }
           iter += mb_len (cur);
         }
+#endif
       return NULL;
     }
   else
index 090d12531bf55350feceda88b4cd1150cb22e4a3..9ff42977b0f9885f9b1e167a2b06f90354b1d995 100644 (file)
 #include <string.h>
 
 #include <ctype.h>
+#include <stdlib.h>
 
-#include "mbuiterf.h"
+#if GNULIB_MCEL_PREFER
+# include "mcel.h"
+#else
+# include "mbuiterf.h"
+#endif
 
 /* Compare the initial segment of the character string STRING consisting of
    at most mbslen (PREFIX) characters with the character string PREFIX,
@@ -47,6 +52,18 @@ mbspcasecmp (const char *string, const char *prefix)
      most often already in the very few first characters.  */
   if (MB_CUR_MAX > 1)
     {
+#if GNULIB_MCEL_PREFER
+      while (*iter2)
+        {
+          if (!*iter1)
+            return NULL;
+          mcel_t g1 = mcel_scanz (iter1); iter1 += g1.len;
+          mcel_t g2 = mcel_scanz (iter2); iter2 += g2.len;
+          if (mcel_tocmp (c32tolower, g1, g2) != 0)
+            return NULL;
+        }
+      return (char *) iter1;
+#else
       mbuif_state_t state1;
       mbuif_init (state1);
 
@@ -71,6 +88,7 @@ mbspcasecmp (const char *string, const char *prefix)
       else
         /* STRING terminated before PREFIX.  */
         return NULL;
+#endif
     }
   else
     for (;; iter1++, iter2++)
index 31df5d1cef33035c03e6905e60c36d99190f9a31..d0734c384c5c2e7714bf4a401e5c3749fd80fb46 100644 (file)
 
 #include <stdlib.h>
 
-#include "mbuiterf.h"
+#if GNULIB_MCEL_PREFER
+# include "mcel.h"
+#else
+# include "mbuiterf.h"
+#endif
 
 char *
 mbssep (char **stringp, const char *delim)
@@ -30,7 +34,6 @@ mbssep (char **stringp, const char *delim)
   if (MB_CUR_MAX > 1)
     {
       char *start = *stringp;
-      char *ptr;
 
       if (start == NULL)
         return NULL;
@@ -38,24 +41,25 @@ mbssep (char **stringp, const char *delim)
       /* No need to optimize the cases of 0 or 1 delimiters specially,
          since mbspbrk already optimizes them.  */
 
-      ptr = mbspbrk (start, delim);
+      char *ptr = mbspbrk (start, delim);
 
       if (ptr == NULL)
-        {
-          *stringp = NULL;
-          return start;
-        }
+        *stringp = NULL;
       else
         {
+#if GNULIB_MCEL_PREFER
+          *stringp = ptr + mcel_scanz (ptr).len;
+#else
           mbuif_state_t state;
           mbuif_init (state);
           if (!mbuif_avail (state, ptr))
             abort ();
           mbchar_t cur = mbuif_next (state, ptr);
-          *ptr = '\0';
           *stringp = ptr + mb_len (cur);
-          return start;
+#endif
+          *ptr = '\0';
         }
+      return start;
     }
   else
     return strsep (stringp, delim);
index 5e3832b72c80f18300f32b80c787c19a9046a3fa..b74a5dd8753f38cf4a8a63499af9e6533e702701 100644 (file)
 /* Specification.  */
 #include <string.h>
 
-#include "mbuiterf.h"
+#include <stdlib.h>
+
+#if GNULIB_MCEL_PREFER
+# include "mcel.h"
+#else
+# include "mbuiterf.h"
+#endif
 
 /* Find the first occurrence in the character string STRING of any character
    not in the character string REJECT.  Return the number of bytes from the
@@ -35,33 +41,66 @@ mbsspn (const char *string, const char *reject)
   if (reject[1] == '\0')
     {
       unsigned char uc = (unsigned char) reject[0];
+      const char *iter = string;
 
       if (MB_CUR_MAX > 1)
         {
+#if GNULIB_MCEL_PREFER
+          for (mcel_t g; *iter; iter += g.len)
+            {
+              g = mcel_scanz (iter);
+              if (! (g.len == 1 && (unsigned char) *iter == uc))
+                break;
+            }
+#else
           mbuif_state_t state;
-          const char *iter;
-          for (mbuif_init (state), iter = string; mbuif_avail (state, iter); )
+          for (mbuif_init (state); mbuif_avail (state, iter); )
             {
               mbchar_t cur = mbuif_next (state, iter);
               if (!(mb_len (cur) == 1 && (unsigned char) *iter == uc))
                 break;
               iter += mb_len (cur);
             }
-          return iter - string;
+#endif
         }
       else
         {
-          const char *ptr;
-
-          for (ptr = string; *ptr != '\0'; ptr++)
-            if ((unsigned char) *ptr != uc)
+          for (; *iter != '\0'; iter++)
+            if ((unsigned char) *iter != uc)
               break;
-          return ptr - string;
         }
+      return iter - string;
     }
   /* General case.  */
   if (MB_CUR_MAX > 1)
     {
+#if GNULIB_MCEL_PREFER
+      for (size_t i = 0; ; )
+        {
+          char c = string[i];
+          if (!c)
+            return i;
+          mcel_t g = mcel_scanz (string + i);
+          if (g.len == 1)
+            {
+              if (!mbschr (reject, c))
+                return i;
+            }
+          else
+            {
+              for (char const *aiter = reject; ; )
+                {
+                  if (!*aiter)
+                    return i;
+                  mcel_t a = mcel_scanz (aiter);
+                  if (mcel_cmp (a, g) == 0)
+                    break;
+                  aiter += a.len;
+                }
+            }
+          i += g.len;
+        }
+#else
       mbuif_state_t state;
       const char *iter;
       for (mbuif_init (state), iter = string; mbuif_avail (state, iter); )
@@ -90,6 +129,7 @@ mbsspn (const char *string, const char *reject)
         }
      found:
       return iter - string;
+#endif
     }
   else
     return strspn (string, reject);
index cfc05ad1398a4eb9ec9e8a17de1c83aafd9f62e2..45fac5abce3bdbab630d3dd12aecd451364c8e30 100644 (file)
 
 #include <string.h>
 
-#include "mbuiter.h"
+#if GNULIB_MCEL_PREFER
+# include "mcel.h"
+#else
+# include "mbuiter.h"
+#endif
+
 #include "xalloc.h"
 
 /* Characters that are special in a BRE.  */
@@ -138,6 +143,16 @@ regex_quote_length (const char *string, const struct regex_quote_spec *spec)
     length += 2; /* for '^' at the beginning and '$' at the end */
   if (spec->multibyte)
     {
+#if GNULIB_MCEL_PREFER
+      char const *iter = string;
+      for (mcel_t g; *iter; iter += g.len)
+        {
+          g = mcel_scanz (iter);
+          /* We know that special contains only ASCII characters.  */
+          length += g.len == 1 && strchr (special, *iter);
+        }
+      length += iter - string;
+#else
       mbui_iterator_t iter;
 
       for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter))
@@ -148,6 +163,7 @@ regex_quote_length (const char *string, const struct regex_quote_spec *spec)
             length += 1;
           length += mb_len (mbui_cur (iter));
         }
+#endif
     }
   else
     {
@@ -173,6 +189,17 @@ regex_quote_copy (char *p, const char *string, const struct regex_quote_spec *sp
     *p++ = '^';
   if (spec->multibyte)
     {
+#if GNULIB_MCEL_PREFER
+      for (char const *iter = string; *iter; )
+        {
+          mcel_t g = mcel_scanz (iter);
+          *p = '\\';
+          /* We know that special contains only ASCII characters.  */
+          p += g.len == 1 && strchr (special, *iter);
+          p = mempcpy (p, iter, g.len);
+          iter += g.len;
+        }
+#else
       mbui_iterator_t iter;
 
       for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter))
index 0034893cd0de86935c11b533c6b519f9dbd92b6f..856c84b3619c7b56694828fdcc4958330e029e06 100644 (file)
@@ -6,6 +6,7 @@ lib/mbmemcasecmp.h
 lib/mbmemcasecmp.c
 
 Depends-on:
+c32tolower
 mbiterf
 
 configure.ac:
index 9d6e2af5ce34a66698cc9b59cd1b2863c406dec9..e01a1a8652bed3a7e85680f1dd3c1dce4c39e874 100644 (file)
@@ -5,6 +5,7 @@ Files:
 lib/mbsncasecmp.c
 
 Depends-on:
+c32tolower
 mbuiterf
 string
 
index 7f2b463aaa4d46f6ed4960daae915153b3f1a101..ffb58bc4f6fc8aa9ee0490dec4047737054c1c46 100644 (file)
@@ -5,6 +5,7 @@ Files:
 lib/mbspcasecmp.c
 
 Depends-on:
+c32tolower
 mbuiterf
 string
 
index c88d14f95a08a76a1a33608fbf639393351ac20b..bdfaeb7d9d51b19d174d4dbedf22cb56a9cb4711 100644 (file)
@@ -9,6 +9,7 @@ Depends-on:
 stdbool
 xalloc
 mbuiter
+mempcpy
 
 configure.ac:
 AC_REQUIRE([AC_C_RESTRICT])