]> Savannah Git Hosting - gnulib.git/commitdiff
mbslen: support GNULIB_MCEL_PREFER
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 9 Sep 2023 22:47:27 +0000 (15:47 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 10 Sep 2023 01:11:43 +0000 (18:11 -0700)
Support mcel API for apps that prefer it.
The following changes are in effect only if GNULIB_MCEL_PREFER.
* lib/mbslen.c: Include mcel.h instead of mbuiterf.h.
(mbslen): Use mcel API.

ChangeLog
lib/mbslen.c

index 5929236789c3bf4fe90fa66a74e3bcd578b400d2..fe2864b0ee5764e6636fa9c448e6f338ed49d761 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2023-09-09  Paul Eggert  <eggert@cs.ucla.edu>
 
+       mbslen: support GNULIB_MCEL_PREFER
+       Support mcel API for apps that prefer it.
+       The following changes are in effect only if GNULIB_MCEL_PREFER.
+       * lib/mbslen.c: Include mcel.h instead of mbuiterf.h.
+       (mbslen): Use mcel API.
+
        chown: work around symlink issues on odd platforms
        Problem reported by Jordi Sanfeliu in:
        https://lists.gnu.org/archive/html/bug-gnulib/2023-07/msg00116.html
index 18642f55e96096efe206cf90c6affb349bf3d7d2..db9fa70d6351e29df5b48f535f1d4286b2828233 100644 (file)
 
 #include <stdlib.h>
 
-#include "mbuiterf.h"
+#if GNULIB_MCEL_PREFER
+# include "mcel.h"
+#else
+# include "mbuiterf.h"
+#endif
 
 /* Return the number of multibyte characters in the character string STRING.  */
 size_t
@@ -32,6 +36,10 @@ mbslen (const char *string)
     {
       size_t count = 0;
 
+#if GNULIB_MCEL_PREFER
+      for (; *string; string += mcel_scanz (string).len)
+        count++;
+#else
       mbuif_state_t state;
       const char *iter;
       for (mbuif_init (state), iter = string; mbuif_avail (state, iter); )
@@ -40,6 +48,7 @@ mbslen (const char *string)
           count++;
           iter += mb_len (cur);
         }
+#endif
 
       return count;
     }