+2007-02-11 Bruno Haible <bruno@clisp.org>
+
+ New module mbslen.
+ * modules/mbslen: New file.
+ * lib/mbslen.c: New file.
+ * lib/string_.h (mbslen): New declaration.
+ * m4/mbslen.m4: New file.
+ * m4/string_h.m4 (gl_STRING_MODULE_INDICATOR_DEFAULTS): Initialize
+ GNULIB_MBSLEN.
+ * modules/string (string.h): Also substitute GNULIB_MBSLEN.
+ * MODULES.html.sh (Internationalization functions): Add mbslen.
+
2007-02-11 Bruno Haible <bruno@clisp.org>
Ensure O(n) worst-case complexity of strcasestr substitute.
func_module iconvme
func_module localcharset
func_module hard-locale
+ func_module mbslen
func_module mbschr
func_module mbsrchr
func_module mbsstr
--- /dev/null
+/* Counting the multibyte characters in a string.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Written by Bruno Haible <bruno@clisp.org>, 2007.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#include <config.h>
+
+/* Specification. */
+#include <string.h>
+
+#if HAVE_MBRTOWC
+# include "mbuiter.h"
+#endif
+
+/* Return the number of multibyte characters in the character string STRING. */
+size_t
+mbslen (const char *string)
+{
+#if HAVE_MBRTOWC
+ if (MB_CUR_MAX > 1)
+ {
+ size_t count;
+ mbui_iterator_t iter;
+
+ count = 0;
+ for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter))
+ count++;
+
+ return count;
+ }
+ else
+#endif
+ return strlen (string);
+}
/* The following functions are not specified by POSIX. They are gnulib
extensions. */
+#if @GNULIB_MBSLEN@
+/* Return the number of multibyte characters in the character string STRING.
+ This considers multibyte characters, unlike strlen, which counts bytes. */
+extern size_t mbslen (const char *string);
+#endif
+
#if @GNULIB_MBSCHR@
/* Locate the first single-byte character C in the character string STRING,
and return a pointer to it. Return NULL if C is not found in STRING.
--- /dev/null
+# mbslen.m4 serial 1
+dnl Copyright (C) 2007 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_MBSLEN],
+[
+ gl_PREREQ_MBSLEN
+])
+
+# Prerequisites of lib/mbslen.c.
+AC_DEFUN([gl_PREREQ_MBSLEN], [
+ AC_REQUIRE([gl_FUNC_MBRTOWC])
+ :
+])
GNULIB_STRSEP=0; AC_SUBST([GNULIB_STRSEP])
GNULIB_STRCASESTR=0; AC_SUBST([GNULIB_STRCASESTR])
GNULIB_STRTOK_R=0; AC_SUBST([GNULIB_STRTOK_R])
+ GNULIB_MBSLEN=0; AC_SUBST([GNULIB_MBSLEN])
GNULIB_MBSCHR=0; AC_SUBST([GNULIB_MBSCHR])
GNULIB_MBSRCHR=0; AC_SUBST([GNULIB_MBSRCHR])
GNULIB_MBSSTR=0; AC_SUBST([GNULIB_MBSSTR])
--- /dev/null
+Description:
+mbslen() function: Determine the number of multibyte characters in a string.
+
+Files:
+lib/mbslen.c
+m4/mbslen.m4
+m4/mbrtowc.m4
+
+Depends-on:
+mbuiter
+string
+
+configure.ac:
+gl_FUNC_MBSLEN
+gl_STRING_MODULE_INDICATOR([mbslen])
+
+Makefile.am:
+lib_SOURCES += mbslen.c
+
+Include:
+<string.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
rm -f $@-t $@
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
sed -e 's|@''ABSOLUTE_STRING_H''@|$(ABSOLUTE_STRING_H)|g' \
+ -e 's|@''GNULIB_MBSLEN''@|$(GNULIB_MBSLEN)|g' \
-e 's|@''GNULIB_MBSCHR''@|$(GNULIB_MBSCHR)|g' \
-e 's|@''GNULIB_MBSRCHR''@|$(GNULIB_MBSRCHR)|g' \
-e 's|@''GNULIB_MBSSTR''@|$(GNULIB_MBSSTR)|g' \