bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

new module 'mbsnlen'


From: Bruno Haible
Subject: new module 'mbsnlen'
Date: Mon, 11 Jun 2007 02:28:30 +0200
User-agent: KMail/1.5.4

A function which counts the number of characters in a memory region can be
useful, and is needed for some vasnprintf variants.

2007-06-10  Bruno Haible  <address@hidden>

        * 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.

*** lib/string_.h       30 May 2007 02:16:52 -0000      1.33
--- lib/string_.h       11 Jun 2007 00:22:09 -0000
***************
*** 401,406 ****
--- 401,412 ----
  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.
============================== lib/mbsnlen.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>

#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;
}
============================== m4/mbsnlen.m4 ===============================
# 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])
  :
])
============================= modules/mbsnlen ==============================
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

============================================================================
*** MODULES.html.sh     9 Jun 2007 21:59:21 -0000       1.215
--- MODULES.html.sh     11 Jun 2007 00:22:09 -0000
***************
*** 2267,2272 ****
--- 2267,2273 ----
    func_module localcharset
    func_module hard-locale
    func_module mbslen
+   func_module mbsnlen
    func_module mbschr
    func_module mbsrchr
    func_module mbsstr
*** m4/string_h.m4      18 Feb 2007 00:19:41 -0000      1.21
--- m4/string_h.m4      11 Jun 2007 00:22:09 -0000
***************
*** 46,51 ****
--- 46,52 ----
    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])
*** modules/string      17 May 2007 06:14:30 -0000      1.21
--- modules/string      11 Jun 2007 00:22:09 -0000
***************
*** 24,29 ****
--- 24,30 ----
          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' \





reply via email to

[Prev in Thread] Current Thread [Next in Thread]