Mercurial > hg > octave-shane > gnulib-hg
changeset 14300:31285699a61f
New module 'wcspbrk'.
* modules/wcspbrk: New file.
* lib/wchar.in.h (wcspbrk): New declaration.
* lib/wcspbrk.c: New file.
* lib/wcspbrk-impl.h: New file, from libutf8 with modifications.
* m4/wcspbrk.m4: New file.
* m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcspbrk is declared.
(gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSPBRK, HAVE_WCSPBRK.
* modules/wchar (Makefile.am): Substitute GNULIB_WCSPBRK, HAVE_WCSPBRK.
* tests/test-wchar-c++.cc: Test the declaration of wcspbrk.
* doc/posix-functions/wcspbrk.texi: Mention the new module.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 06 Feb 2011 14:34:38 +0100 |
parents | 0d372bfa8a0f |
children | b58bcfabff09 |
files | ChangeLog doc/posix-functions/wcspbrk.texi lib/wchar.in.h lib/wcspbrk-impl.h lib/wcspbrk.c m4/wchar_h.m4 m4/wcspbrk.m4 modules/wchar modules/wcspbrk tests/test-wchar-c++.cc |
diffstat | 10 files changed, 163 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2011-02-06 Bruno Haible <bruno@clisp.org> + + New module 'wcspbrk'. + * modules/wcspbrk: New file. + * lib/wchar.in.h (wcspbrk): New declaration. + * lib/wcspbrk.c: New file. + * lib/wcspbrk-impl.h: New file, from libutf8 with modifications. + * m4/wcspbrk.m4: New file. + * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcspbrk is declared. + (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSPBRK, HAVE_WCSPBRK. + * modules/wchar (Makefile.am): Substitute GNULIB_WCSPBRK, HAVE_WCSPBRK. + * tests/test-wchar-c++.cc: Test the declaration of wcspbrk. + * doc/posix-functions/wcspbrk.texi: Mention the new module. + 2011-02-06 Bruno Haible <bruno@clisp.org> New module 'wcsspn'.
--- a/doc/posix-functions/wcspbrk.texi +++ b/doc/posix-functions/wcspbrk.texi @@ -4,18 +4,18 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcspbrk.html} -Gnulib module: --- +Gnulib module: wcspbrk Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +IRIX 5.3, Solaris 2.5.1. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on some platforms: -IRIX 5.3, Solaris 2.5.1. -@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 @@ -837,6 +837,24 @@ #endif +/* Find the first occurrence in WCS of any character in ACCEPT. */ +#if @GNULIB_WCSPBRK@ +# if !@HAVE_WCSPBRK@ +_GL_FUNCDECL_SYS (wcspbrk, wchar_t *, + (const wchar_t *wcs, const wchar_t *accept)); +# endif +_GL_CXXALIAS_SYS (wcspbrk, wchar_t *, + (const wchar_t *wcs, const wchar_t *accept)); +_GL_CXXALIASWARN (wcspbrk); +#elif defined GNULIB_POSIXCHECK +# undef wcspbrk +# if HAVE_RAW_DECL_WCSPBRK +_GL_WARN_ON_USE (wcspbrk, "wcspbrk is unportable - " + "use gnulib module wcspbrk for portability"); +# endif +#endif + + #endif /* _GL_WCHAR_H */ #endif /* _GL_WCHAR_H */ #endif
new file mode 100644 --- /dev/null +++ b/lib/wcspbrk-impl.h @@ -0,0 +1,47 @@ +/* Search a wide string for any of a set of wide characters. + 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/>. */ + +wchar_t * +wcspbrk (const wchar_t *wcs, const wchar_t *accept) +{ + /* Optimize two cases. */ + if (accept[0] == (wchar_t)'\0') + return NULL; + + if (accept[1] == (wchar_t)'\0') + { + wchar_t wc = accept[0]; + const wchar_t *ptr = wcs; + for (; *ptr != (wchar_t)'\0'; ptr++) + { + if (*ptr == wc) + return (wchar_t *) ptr; + } + return NULL; + } + + /* General case. */ + { + const wchar_t *ptr = wcs; + for (; *ptr != (wchar_t)'\0'; ptr++) + { + if (wcschr (accept, *ptr)) + return (wchar_t *) ptr; + } + return NULL; + } +}
new file mode 100644 --- /dev/null +++ b/lib/wcspbrk.c @@ -0,0 +1,23 @@ +/* Search a wide string for any of a set of wide characters. + 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 "wcspbrk-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 + wcscspn wcsspn wcspbrk ]) ]) @@ -172,6 +172,7 @@ GNULIB_WCSRCHR=0; AC_SUBST([GNULIB_WCSRCHR]) GNULIB_WCSCSPN=0; AC_SUBST([GNULIB_WCSCSPN]) GNULIB_WCSSPN=0; AC_SUBST([GNULIB_WCSSPN]) + GNULIB_WCSPBRK=0; AC_SUBST([GNULIB_WCSPBRK]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC]) HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT]) @@ -206,6 +207,7 @@ HAVE_WCSRCHR=1; AC_SUBST([HAVE_WCSRCHR]) HAVE_WCSCSPN=1; AC_SUBST([HAVE_WCSCSPN]) HAVE_WCSSPN=1; AC_SUBST([HAVE_WCSSPN]) + HAVE_WCSPBRK=1; AC_SUBST([HAVE_WCSPBRK]) 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])
new file mode 100644 --- /dev/null +++ b/m4/wcspbrk.m4 @@ -0,0 +1,15 @@ +# wcspbrk.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_WCSPBRK], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + AC_CHECK_FUNCS_ONCE([wcspbrk]) + if test $ac_cv_func_wcspbrk = no; then + HAVE_WCSPBRK=0 + AC_LIBOBJ([wcspbrk]) + fi +])
--- a/modules/wchar +++ b/modules/wchar @@ -65,6 +65,7 @@ -e 's|@''GNULIB_WCSRCHR''@|$(GNULIB_WCSRCHR)|g' \ -e 's|@''GNULIB_WCSCSPN''@|$(GNULIB_WCSCSPN)|g' \ -e 's|@''GNULIB_WCSSPN''@|$(GNULIB_WCSSPN)|g' \ + -e 's|@''GNULIB_WCSPBRK''@|$(GNULIB_WCSPBRK)|g' \ -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \ -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \ -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \ @@ -99,6 +100,7 @@ -e 's|@''HAVE_WCSRCHR''@|$(HAVE_WCSRCHR)|g' \ -e 's|@''HAVE_WCSCSPN''@|$(HAVE_WCSCSPN)|g' \ -e 's|@''HAVE_WCSSPN''@|$(HAVE_WCSSPN)|g' \ + -e 's|@''HAVE_WCSPBRK''@|$(HAVE_WCSPBRK)|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' \
new file mode 100644 --- /dev/null +++ b/modules/wcspbrk @@ -0,0 +1,32 @@ +Description: +wcspbrk() function: search a wide string for any of a set of wide characters. + +Status: +obsolete + +Notice: +This module is obsolete. + +Files: +lib/wcspbrk.c +lib/wcspbrk-impl.h +m4/wcspbrk.m4 + +Depends-on: +wchar +wcschr + +configure.ac: +gl_FUNC_WCSPBRK +gl_WCHAR_MODULE_INDICATOR([wcspbrk]) + +Makefile.am: + +Include: +<wchar.h> + +License: +LGPL + +Maintainer: +Bruno Haible