Mercurial > hg > octave-kai > gnulib-hg
changeset 14303:7357862f4745
New module 'wcswidth'.
* modules/wcswidth: New file.
* lib/wchar.in.h (wcswidth): New declaration.
* lib/wcswidth.c: New file.
* lib/wcswidth-impl.h: New file, from libutf8 with modifications.
* m4/wcswidth.m4: New file.
* m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcswidth is declared.
(gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSWIDTH, HAVE_WCSWIDTH,
REPLACE_WCSWIDTH.
* modules/wchar (Makefile.am): Substitute GNULIB_WCSWIDTH,
HAVE_WCSWIDTH, REPLACE_WCSWIDTH.
* tests/test-wchar-c++.cc: Test the declaration of wcswidth.
* doc/posix-functions/wcswidth.texi: Mention the new module.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 06 Feb 2011 15:51:55 +0100 |
parents | 952e98e7b703 |
children | 550f5258de22 |
files | ChangeLog doc/posix-functions/wcswidth.texi lib/wchar.in.h lib/wcswidth-impl.h lib/wcswidth.c m4/wchar_h.m4 m4/wcswidth.m4 modules/wchar modules/wcswidth tests/test-wchar-c++.cc |
diffstat | 10 files changed, 173 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2011-02-06 Bruno Haible <bruno@clisp.org> + + New module 'wcswidth'. + * modules/wcswidth: New file. + * lib/wchar.in.h (wcswidth): New declaration. + * lib/wcswidth.c: New file. + * lib/wcswidth-impl.h: New file, from libutf8 with modifications. + * m4/wcswidth.m4: New file. + * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcswidth is declared. + (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSWIDTH, HAVE_WCSWIDTH, + REPLACE_WCSWIDTH. + * modules/wchar (Makefile.am): Substitute GNULIB_WCSWIDTH, + HAVE_WCSWIDTH, REPLACE_WCSWIDTH. + * tests/test-wchar-c++.cc: Test the declaration of wcswidth. + * doc/posix-functions/wcswidth.texi: Mention the new module. + 2011-02-06 Bruno Haible <bruno@clisp.org> New module 'wcstok'.
--- a/doc/posix-functions/wcswidth.texi +++ b/doc/posix-functions/wcswidth.texi @@ -4,18 +4,22 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcswidth.html} -Gnulib module: --- +Gnulib module: wcswidth Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +OpenBSD 3.8, IRIX 5.3, Solaris 2.5.1, mingw, BeOS. +@item +This function handles combining characters in UTF-8 locales incorrectly on some +platforms: +MacOS X 10.3. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on some platforms: -OpenBSD 3.8, IRIX 5.3, Solaris 2.5.1, mingw, BeOS. -@item On AIX and Windows platforms, @code{wchar_t} is a 16-bit type and therefore cannot accommodate all Unicode characters. @end itemize
--- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -891,6 +891,32 @@ #endif +/* Determine number of column positions required for first N wide + characters (or fewer if S ends before this) in S. */ +#if @GNULIB_WCSWIDTH@ +# if @REPLACE_WCSWIDTH@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcswidth +# define wcswidth rpl_wcswidth +# endif +_GL_FUNCDECL_RPL (wcswidth, int, (const wchar_t *s, size_t n)); +_GL_CXXALIAS_RPL (wcswidth, int, (const wchar_t *s, size_t n)); +# else +# if !@HAVE_WCSWIDTH@ +_GL_FUNCDECL_SYS (wcswidth, int, (const wchar_t *s, size_t n)); +# endif +_GL_CXXALIAS_SYS (wcswidth, int, (const wchar_t *s, size_t n)); +# endif +_GL_CXXALIASWARN (wcswidth); +#elif defined GNULIB_POSIXCHECK +# undef wcswidth +# if HAVE_RAW_DECL_WCSWIDTH +_GL_WARN_ON_USE (wcswidth, "wcswidth is unportable - " + "use gnulib module wcswidth for portability"); +# endif +#endif + + #endif /* _GL_WCHAR_H */ #endif /* _GL_WCHAR_H */ #endif
new file mode 100644 --- /dev/null +++ b/lib/wcswidth-impl.h @@ -0,0 +1,38 @@ +/* Determine number of screen columns needed for a size-bounded wide string. + Copyright (C) 1999, 2011 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 1999. + + 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 3 of the License, 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, see <http://www.gnu.org/licenses/>. */ + +int +wcswidth (const wchar_t *s, size_t n) +{ + int count = 0; + for (; n > 0; s++, n--) + { + wchar_t c = *s; + if (c == (wchar_t)'\0') + break; + { + int width = wcwidth (c); + if (width < 0) + goto found_nonprinting; + count += width; + } + } + return count; + + found_nonprinting: + return -1; +}
new file mode 100644 --- /dev/null +++ b/lib/wcswidth.c @@ -0,0 +1,23 @@ +/* Determine number of screen columns needed for a size-bounded wide string. + Copyright (C) 2011 Free Software Foundation, Inc. + Written by Bruno Haible <bruno@clisp.org>, 2011. + + 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 3 of the License, 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, see <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include <wchar.h> + +#include "wcswidth-impl.h"
--- a/m4/wchar_h.m4 +++ b/m4/wchar_h.m4 @@ -53,7 +53,7 @@ wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy wmemmove wmemset wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr - wcscspn wcsspn wcspbrk wcsstr wcstok + wcscspn wcsspn wcspbrk wcsstr wcstok wcswidth ]) ]) @@ -175,6 +175,7 @@ GNULIB_WCSPBRK=0; AC_SUBST([GNULIB_WCSPBRK]) GNULIB_WCSSTR=0; AC_SUBST([GNULIB_WCSSTR]) GNULIB_WCSTOK=0; AC_SUBST([GNULIB_WCSTOK]) + GNULIB_WCSWIDTH=0; AC_SUBST([GNULIB_WCSWIDTH]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC]) HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT]) @@ -212,6 +213,7 @@ HAVE_WCSPBRK=1; AC_SUBST([HAVE_WCSPBRK]) HAVE_WCSSTR=1; AC_SUBST([HAVE_WCSSTR]) HAVE_WCSTOK=1; AC_SUBST([HAVE_WCSTOK]) + HAVE_WCSWIDTH=1; AC_SUBST([HAVE_WCSWIDTH]) HAVE_DECL_WCTOB=1; AC_SUBST([HAVE_DECL_WCTOB]) HAVE_DECL_WCWIDTH=1; AC_SUBST([HAVE_DECL_WCWIDTH]) REPLACE_MBSTATE_T=0; AC_SUBST([REPLACE_MBSTATE_T]) @@ -226,4 +228,5 @@ REPLACE_WCSRTOMBS=0; AC_SUBST([REPLACE_WCSRTOMBS]) REPLACE_WCSNRTOMBS=0; AC_SUBST([REPLACE_WCSNRTOMBS]) REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH]) + REPLACE_WCSWIDTH=0; AC_SUBST([REPLACE_WCSWIDTH]) ])
new file mode 100644 --- /dev/null +++ b/m4/wcswidth.m4 @@ -0,0 +1,24 @@ +# wcswidth.m4 serial 1 +dnl Copyright (C) 2011 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_WCSWIDTH], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + AC_REQUIRE([gl_FUNC_WCWIDTH]) + AC_CHECK_FUNCS_ONCE([wcswidth]) + if test $ac_cv_func_wcswidth = no; then + HAVE_WCSWIDTH=0 + else + if test $REPLACE_WCWIDTH = 1; then + dnl If wcwidth needed to be replaced, wcswidth needs to be replaced + dnl as well. + REPLACE_WCSWIDTH=1 + fi + fi + if test $HAVE_WCSWIDTH = 0 || test $REPLACE_WCSWIDTH = 1; then + AC_LIBOBJ([wcswidth]) + fi +])
--- a/modules/wchar +++ b/modules/wchar @@ -68,6 +68,7 @@ -e 's|@''GNULIB_WCSPBRK''@|$(GNULIB_WCSPBRK)|g' \ -e 's|@''GNULIB_WCSSTR''@|$(GNULIB_WCSSTR)|g' \ -e 's|@''GNULIB_WCSTOK''@|$(GNULIB_WCSTOK)|g' \ + -e 's|@''GNULIB_WCSWIDTH''@|$(GNULIB_WCSWIDTH)|g' \ -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \ -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \ -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \ @@ -105,6 +106,7 @@ -e 's|@''HAVE_WCSPBRK''@|$(HAVE_WCSPBRK)|g' \ -e 's|@''HAVE_WCSSTR''@|$(HAVE_WCSSTR)|g' \ -e 's|@''HAVE_WCSTOK''@|$(HAVE_WCSTOK)|g' \ + -e 's|@''HAVE_WCSWIDTH''@|$(HAVE_WCSWIDTH)|g' \ -e 's|@''HAVE_DECL_WCTOB''@|$(HAVE_DECL_WCTOB)|g' \ -e 's|@''HAVE_DECL_WCWIDTH''@|$(HAVE_DECL_WCWIDTH)|g' \ -e 's|@''REPLACE_MBSTATE_T''@|$(REPLACE_MBSTATE_T)|g' \ @@ -119,6 +121,7 @@ -e 's|@''REPLACE_WCSRTOMBS''@|$(REPLACE_WCSRTOMBS)|g' \ -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \ -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \ + -e 's|@''REPLACE_WCSWIDTH''@|$(REPLACE_WCSWIDTH)|g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
new file mode 100644 --- /dev/null +++ b/modules/wcswidth @@ -0,0 +1,27 @@ +Description: +wcswidth() function: determine number of screen columns needed for a +size-bounded wide string. + +Files: +lib/wcswidth.c +lib/wcswidth-impl.h +m4/wcswidth.m4 + +Depends-on: +wchar +wcwidth + +configure.ac: +gl_FUNC_WCSWIDTH +gl_WCHAR_MODULE_INDICATOR([wcswidth]) + +Makefile.am: + +Include: +<wchar.h> + +License: +LGPL + +Maintainer: +Bruno Haible