From 60ed215df062bdeef13b2cef7a9aa1956a070248 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 11 Jun 2007 00:29:30 +0000 Subject: [PATCH] New module 'mbsnlen'. --- ChangeLog | 10 ++++++++++ MODULES.html.sh | 1 + lib/mbsnlen.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/string_.h | 6 ++++++ m4/mbsnlen.m4 | 16 ++++++++++++++++ m4/string_h.m4 | 1 + modules/mbsnlen | 28 ++++++++++++++++++++++++++++ modules/string | 1 + 8 files changed, 113 insertions(+) create mode 100644 lib/mbsnlen.c create mode 100644 m4/mbsnlen.m4 create mode 100644 modules/mbsnlen diff --git a/ChangeLog b/ChangeLog index 662e0581a..376c898fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2007-06-10 Bruno Haible + * 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 + * lib/mbslen.c: Include , needed for MB_CUR_MAX. 2007-06-10 Bruno Haible diff --git a/MODULES.html.sh b/MODULES.html.sh index 86b789311..ae39dc207 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -2267,6 +2267,7 @@ func_all_modules () func_module localcharset func_module hard-locale func_module mbslen + func_module mbsnlen func_module mbschr func_module mbsrchr func_module mbsstr diff --git a/lib/mbsnlen.c b/lib/mbsnlen.c new file mode 100644 index 000000000..4cd33584b --- /dev/null +++ b/lib/mbsnlen.c @@ -0,0 +1,50 @@ +/* Counting the multibyte characters in a string. + Copyright (C) 2007 Free Software Foundation, Inc. + Written by Bruno Haible , 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 + +/* Specification. */ +#include + +#include + +#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; +} diff --git a/lib/string_.h b/lib/string_.h index 6ec72c3e7..4dbe66ccc 100644 --- a/lib/string_.h +++ b/lib/string_.h @@ -401,6 +401,12 @@ extern char *strtok_r (char *restrict s, char const *restrict delim, 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. diff --git a/m4/mbsnlen.m4 b/m4/mbsnlen.m4 new file mode 100644 index 000000000..1b715ddb6 --- /dev/null +++ b/m4/mbsnlen.m4 @@ -0,0 +1,16 @@ +# 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]) + : +]) diff --git a/m4/string_h.m4 b/m4/string_h.m4 index f706d491b..ab5d78698 100644 --- a/m4/string_h.m4 +++ b/m4/string_h.m4 @@ -46,6 +46,7 @@ AC_DEFUN([gl_HEADER_STRING_H_DEFAULTS], 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]) diff --git a/modules/mbsnlen b/modules/mbsnlen new file mode 100644 index 000000000..59f0f942e --- /dev/null +++ b/modules/mbsnlen @@ -0,0 +1,28 @@ +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: + + +License: +LGPL + +Maintainer: +Bruno Haible + diff --git a/modules/string b/modules/string index 1624d69ee..b0f715095 100644 --- a/modules/string +++ b/modules/string @@ -24,6 +24,7 @@ string.h: string_.h 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' \ -- 2.11.0