This creates three variants of mbsnlen function for Unicode strings (rather than multibyte character strings in the locale encoding). They are needed for Unicode-enabled *printf functions.
2007-06-10 Bruno Haible <[EMAIL PROTECTED]> * modules/unistr/u32-mbsnlen: New file. * lib/unistr/u32-mbsnlen.c: New file. * modules/unistr/u16-mbsnlen: New file. * lib/unistr/u16-mbsnlen.c: New file. * modules/unistr/u8-mbsnlen: New file. * lib/unistr/u8-mbsnlen.c: New file. * lib/unistr.h (u8_mbsnlen, u16_mbsnlen, u32_mbsnlen): New declarations. *** lib/unistr.h 28 Mar 2007 21:37:36 -0000 1.9 --- lib/unistr.h 11 Jun 2007 00:30:15 -0000 *************** *** 411,416 **** --- 411,425 ---- extern uint32_t * u32_chr (const uint32_t *s, size_t n, ucs4_t uc); + /* Count the number of Unicode characters in the N units from S. */ + /* Similar to mbsnlen(). */ + extern size_t + u8_mbsnlen (const uint8_t *s, size_t n); + extern size_t + u16_mbsnlen (const uint16_t *s, size_t n); + extern size_t + u32_mbsnlen (const uint32_t *s, size_t n); + /* Elementary string functions with memory allocation. */ /* Make a freshly allocated copy of S, of length N. */ ============================= lib/unistr/u8-mbsnlen.c ======================== /* Count characters in UTF-8 string. Copyright (C) 2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2007. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library 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 Library General Public License for more details. You should have received a copy of the GNU Library 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 "unistr.h" size_t u8_mbsnlen (const uint8_t *s, size_t n) { size_t characters; characters = 0; while (n > 0) { int count = u8_mblen (s, n); if (count <= 0) count = 1; s += count; n -= count; characters++; } return characters; } ============================= lib/unistr/u16-mbsnlen.c ======================== /* Count characters in UTF-16 string. Copyright (C) 2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2007. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library 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 Library General Public License for more details. You should have received a copy of the GNU Library 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 "unistr.h" size_t u16_mbsnlen (const uint16_t *s, size_t n) { size_t characters; characters = 0; while (n > 0) { int count = u16_mblen (s, n); if (count <= 0) count = 1; s += count; n -= count; characters++; } return characters; } ============================= lib/unistr/u32-mbsnlen.c ======================== /* Count characters in UTF-32 string. Copyright (C) 2007 Free Software Foundation, Inc. Written by Bruno Haible <[EMAIL PROTECTED]>, 2007. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library 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 Library General Public License for more details. You should have received a copy of the GNU Library 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 "unistr.h" size_t u32_mbsnlen (const uint32_t *s, size_t n) { return n; } ============================= modules/unistr/u8-mbsnlen ======================= Description: Count characters in UTF-8 string. Files: lib/unistr/u8-mbsnlen.c Depends-on: unistr/base unistr/u8-mblen configure.ac: Makefile.am: lib_SOURCES += unistr/u8-mbsnlen.c Include: "unistr.h" License: LGPL Maintainer: Bruno Haible ============================= modules/unistr/u16-mbsnlen ======================= Description: Count characters in UTF-16 string. Files: lib/unistr/u16-mbsnlen.c Depends-on: unistr/base unistr/u16-mblen configure.ac: Makefile.am: lib_SOURCES += unistr/u16-mbsnlen.c Include: "unistr.h" License: LGPL Maintainer: Bruno Haible ============================= modules/unistr/u32-mbsnlen ======================= Description: Count characters in UTF-32 string. Files: lib/unistr/u32-mbsnlen.c Depends-on: unistr/base configure.ac: Makefile.am: lib_SOURCES += unistr/u32-mbsnlen.c Include: "unistr.h" License: LGPL Maintainer: Bruno Haible