[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
new module 'mbslen'
From: |
Bruno Haible |
Subject: |
new module 'mbslen' |
Date: |
Sun, 11 Feb 2007 18:08:25 +0100 |
User-agent: |
KMail/1.5.4 |
The function 'mbslen' turns out to be a common utility function, needed if
one needs to a memory allocation or similar before iterating through a string.
2007-02-11 Bruno Haible <address@hidden>
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.
=============================== modules/mbslen ===============================
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
================================ lib/mbslen.c ================================
/* Counting the multibyte characters in a string.
Copyright (C) 2007 Free Software Foundation, Inc.
Written by Bruno Haible <address@hidden>, 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);
}
================================ m4/mbslen.m4 ================================
# 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])
:
])
==============================================================================
--- lib/string_.h 6 Feb 2007 01:59:41 -0000 1.19
+++ lib/string_.h 11 Feb 2007 16:57:48 -0000
@@ -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.
--- m4/string_h.m4 6 Feb 2007 01:59:41 -0000 1.17
+++ m4/string_h.m4 11 Feb 2007 16:57:48 -0000
@@ -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])
--- modules/string 6 Feb 2007 01:59:41 -0000 1.16
+++ modules/string 11 Feb 2007 16:57:48 -0000
@@ -21,6 +21,7 @@
rm -f address@hidden $@
{ 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' \
--- MODULES.html.sh 6 Feb 2007 01:59:41 -0000 1.190
+++ MODULES.html.sh 11 Feb 2007 16:57:48 -0000
@@ -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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- new module 'mbslen',
Bruno Haible <=