From 00893e79fc62966067af1a106567db96bd170338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 3 Mar 2024 19:11:32 +0100 Subject: New upstream version 1.2 --- lib/mbsnlen.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'lib/mbsnlen.c') 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 , 2007. This file is free software: you can redistribute it and/or modify @@ -22,7 +22,11 @@ #include -#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; } -- cgit v1.2.3