Mercurial > hg > octave-kai > gnulib-hg
changeset 8126:c534d48f4224
New module 'mbslen'.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 11 Feb 2007 17:02:31 +0000 |
parents | 0545abcdfb09 |
children | 127a096061c8 |
files | ChangeLog MODULES.html.sh lib/mbslen.c lib/string_.h m4/mbslen.m4 m4/string_h.m4 modules/mbslen modules/string |
diffstat | 8 files changed, 112 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +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.
--- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -2160,6 +2160,7 @@ func_module iconvme func_module localcharset func_module hard-locale + func_module mbslen func_module mbschr func_module mbsrchr func_module mbsstr
new file mode 100644 --- /dev/null +++ b/lib/mbslen.c @@ -0,0 +1,47 @@ +/* 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); +}
--- a/lib/string_.h +++ b/lib/string_.h @@ -349,6 +349,12 @@ /* 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.
new file mode 100644 --- /dev/null +++ b/m4/mbslen.m4 @@ -0,0 +1,16 @@ +# 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]) + : +])
--- a/m4/string_h.m4 +++ b/m4/string_h.m4 @@ -67,6 +67,7 @@ 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])
new file mode 100644 --- /dev/null +++ b/modules/mbslen @@ -0,0 +1,28 @@ +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 +
--- a/modules/string +++ b/modules/string @@ -21,6 +21,7 @@ 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' \