+2007-06-10 Bruno Haible <bruno@clisp.org>
+
+ * lib/string_.h (mbsnlen): New declaration.
+ * lib/mbsnlen.c: New file.
+ * m4/mbsnlen.m4: New file.
+ * modules/mbsnlen: New file.
+ * m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Set GNULIB_MBSNLEN.
+ * modules/string (string.h): Substitute GNULIB_MBSNLEN.
+ * MODULES.html.sh (Internationalization functions): Add mbsnlen.
+
2007-06-10 Bruno Haible <bruno@clisp.org>
* lib/mbslen.c: Include <stdlib.h>, needed for MB_CUR_MAX.
func_module localcharset
func_module hard-locale
func_module mbslen
+ func_module mbsnlen
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>
+
+#include <stdlib.h>
+
+#if HAVE_MBRTOWC
+# include "mbiter.h"
+#endif
+
+/* Return the number of multibyte characters in the character string starting
+ at STRING and ending at STRING + LEN. */
+size_t
+mbsnlen (const char *string, size_t len)
+{
+#if HAVE_MBRTOWC
+ if (MB_CUR_MAX > 1)
+ {
+ size_t count;
+ mbi_iterator_t iter;
+
+ count = 0;
+ for (mbi_init (iter, string, len); mbi_avail (iter); mbi_advance (iter))
+ count++;
+
+ return count;
+ }
+ else
+#endif
+ return len;
+}
extern size_t mbslen (const char *string);
#endif
+#if @GNULIB_MBSNLEN@
+/* Return the number of multibyte characters in the character string starting
+ at STRING and ending at STRING + LEN. */
+extern size_t mbsnlen (const char *string, size_t len);
+#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
+# mbsnlen.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_MBSNLEN],
+[
+ gl_PREREQ_MBSNLEN
+])
+
+# Prerequisites of lib/mbsnlen.c.
+AC_DEFUN([gl_PREREQ_MBSNLEN], [
+ AC_REQUIRE([gl_FUNC_MBRTOWC])
+ :
+])
GNULIB_STRCASESTR=0; AC_SUBST([GNULIB_STRCASESTR])
GNULIB_STRTOK_R=0; AC_SUBST([GNULIB_STRTOK_R])
GNULIB_MBSLEN=0; AC_SUBST([GNULIB_MBSLEN])
+ GNULIB_MBSNLEN=0; AC_SUBST([GNULIB_MBSNLEN])
GNULIB_MBSCHR=0; AC_SUBST([GNULIB_MBSCHR])
GNULIB_MBSRCHR=0; AC_SUBST([GNULIB_MBSRCHR])
GNULIB_MBSSTR=0; AC_SUBST([GNULIB_MBSSTR])
--- /dev/null
+Description:
+mbsnlen() function: Determine the number of multibyte characters in a string.
+
+Files:
+lib/mbsnlen.c
+m4/mbsnlen.m4
+m4/mbrtowc.m4
+
+Depends-on:
+mbiter
+string
+
+configure.ac:
+gl_FUNC_MBSNLEN
+gl_STRING_MODULE_INDICATOR([mbsnlen])
+
+Makefile.am:
+lib_SOURCES += mbsnlen.c
+
+Include:
+<string.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
+
sed -e 's|@''ABSOLUTE_STRING_H''@|$(ABSOLUTE_STRING_H)|g' \
-e 's/@''HAVE_INCLUDE_NEXT''@/$(HAVE_INCLUDE_NEXT)/g' \
-e 's|@''GNULIB_MBSLEN''@|$(GNULIB_MBSLEN)|g' \
+ -e 's|@''GNULIB_MBSNLEN''@|$(GNULIB_MBSNLEN)|g' \
-e 's|@''GNULIB_MBSCHR''@|$(GNULIB_MBSCHR)|g' \
-e 's|@''GNULIB_MBSRCHR''@|$(GNULIB_MBSRCHR)|g' \
-e 's|@''GNULIB_MBSSTR''@|$(GNULIB_MBSSTR)|g' \