summaryrefslogtreecommitdiff
path: root/lib/mbsnlen.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2024-03-24 08:54:48 +0100
committerJörg Frings-Fürst <debian@jff.email>2024-03-24 08:54:48 +0100
commit163a663518f33bab48b28431972e580b366b4d49 (patch)
treef518ffabaca4a0b93f0103d617e803792d3b0b43 /lib/mbsnlen.c
parent1b3a8d5ad2ea2f099d514d9dd51ebf926a628076 (diff)
parentdd0000f7e25abe6c28d4329d324fd7fcab54094f (diff)
Merge branch 'release/debian/1.2-1'HEADdebian/1.2-1master
Diffstat (limited to 'lib/mbsnlen.c')
-rw-r--r--lib/mbsnlen.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/mbsnlen.c b/lib/mbsnlen.c
index c6ea1fef..baadf163 100644
--- a/lib/mbsnlen.c
+++ b/lib/mbsnlen.c
@@ -1,5 +1,5 @@
/* Counting the multibyte characters in a string.
- Copyright (C) 2007-2022 Free Software Foundation, Inc.
+ Copyright (C) 2007-2024 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2007.
This file is free software: you can redistribute it and/or modify
@@ -22,7 +22,11 @@
#include <stdlib.h>
-#include "mbiter.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. */
@@ -31,12 +35,23 @@ mbsnlen (const char *string, size_t len)
{
if (MB_CUR_MAX > 1)
{
- size_t count;
- mbi_iterator_t iter;
+ size_t count = 0;
- count = 0;
- for (mbi_init (iter, string, len); mbi_avail (iter); mbi_advance (iter))
+ 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); )
+ {
+ mbchar_t cur = mbif_next (state, iter, string_end);
+ count++;
+ iter += mb_len (cur);
+ }
+#endif
return count;
}