From: Bruno Haible Date: Sun, 6 Feb 2011 13:19:57 +0000 (+0100) Subject: New module 'wcsspn'. X-Git-Tag: v0.1~3224 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=09eadbc764eae5d1bf87c24b057664c8cfa6302b;p=gnulib.git New module 'wcsspn'. * modules/wcsspn: New file. * lib/wchar.in.h (wcsspn): New declaration. * lib/wcsspn.c: New file. * lib/wcsspn-impl.h: New file, from libutf8 with modifications. * m4/wcsspn.m4: New file. * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcsspn is declared. (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSSPN, HAVE_WCSSPN. * modules/wchar (Makefile.am): Substitute GNULIB_WCSSPN, HAVE_WCSSPN. * tests/test-wchar-c++.cc: Test the declaration of wcsspn. * doc/posix-functions/wcsspn.texi: Mention the new module. --- diff --git a/ChangeLog b/ChangeLog index 993962988..acfb63f29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,19 @@ 2011-02-06 Bruno Haible + New module 'wcsspn'. + * modules/wcsspn: New file. + * lib/wchar.in.h (wcsspn): New declaration. + * lib/wcsspn.c: New file. + * lib/wcsspn-impl.h: New file, from libutf8 with modifications. + * m4/wcsspn.m4: New file. + * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcsspn is declared. + (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSSPN, HAVE_WCSSPN. + * modules/wchar (Makefile.am): Substitute GNULIB_WCSSPN, HAVE_WCSSPN. + * tests/test-wchar-c++.cc: Test the declaration of wcsspn. + * doc/posix-functions/wcsspn.texi: Mention the new module. + +2011-02-06 Bruno Haible + New module 'wcscspn'. * modules/wcscspn: New file. * lib/wchar.in.h (wcscspn): New declaration. diff --git a/doc/posix-functions/wcsspn.texi b/doc/posix-functions/wcsspn.texi index f4feb2d73..d4f160120 100644 --- a/doc/posix-functions/wcsspn.texi +++ b/doc/posix-functions/wcsspn.texi @@ -4,18 +4,18 @@ POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcsspn.html} -Gnulib module: --- +Gnulib module: wcsspn 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 diff --git a/lib/wchar.in.h b/lib/wchar.in.h index e9225c65e..121257b80 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -820,6 +820,23 @@ _GL_WARN_ON_USE (wcscspn, "wcscspn is unportable - " #endif +/* Return the length of the initial segmet of WCS which consists entirely + of wide characters in ACCEPT. */ +#if @GNULIB_WCSSPN@ +# if !@HAVE_WCSSPN@ +_GL_FUNCDECL_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept)); +# endif +_GL_CXXALIAS_SYS (wcsspn, size_t, (const wchar_t *wcs, const wchar_t *accept)); +_GL_CXXALIASWARN (wcsspn); +#elif defined GNULIB_POSIXCHECK +# undef wcsspn +# if HAVE_RAW_DECL_WCSSPN +_GL_WARN_ON_USE (wcsspn, "wcsspn is unportable - " + "use gnulib module wcsspn for portability"); +# endif +#endif + + #endif /* _GL_WCHAR_H */ #endif /* _GL_WCHAR_H */ #endif diff --git a/lib/wcsspn-impl.h b/lib/wcsspn-impl.h new file mode 100644 index 000000000..5d13b92ff --- /dev/null +++ b/lib/wcsspn-impl.h @@ -0,0 +1,47 @@ +/* Advance in a wide string, skipping any of a set of wide characters. + Copyright (C) 1999, 2011 Free Software Foundation, Inc. + Written by Bruno Haible , 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 . */ + +size_t +wcsspn (const wchar_t *wcs, const wchar_t *accept) +{ + /* Optimize two cases. */ + if (accept[0] == (wchar_t)'\0') + return 0; + + 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) + break; + } + return ptr - wcs; + } + + /* General case. */ + { + const wchar_t *ptr = wcs; + for (; *ptr != (wchar_t)'\0'; ptr++) + { + if (!wcschr (accept, *ptr)) + break; + } + return ptr - wcs; + } +} diff --git a/lib/wcsspn.c b/lib/wcsspn.c new file mode 100644 index 000000000..1cabf8d4d --- /dev/null +++ b/lib/wcsspn.c @@ -0,0 +1,23 @@ +/* Advance in a wide string, skipping any of a set of wide characters. + Copyright (C) 2011 Free Software Foundation, Inc. + Written by Bruno Haible , 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 . */ + +#include + +/* Specification. */ +#include + +#include "wcsspn-impl.h" diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4 index c86c9e920..84be7259a 100644 --- a/m4/wchar_h.m4 +++ b/m4/wchar_h.m4 @@ -53,7 +53,7 @@ AC_DEFUN([gl_WCHAR_H], 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 + wcscspn wcsspn ]) ]) @@ -171,6 +171,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], GNULIB_WCSCHR=0; AC_SUBST([GNULIB_WCSCHR]) GNULIB_WCSRCHR=0; AC_SUBST([GNULIB_WCSRCHR]) GNULIB_WCSCSPN=0; AC_SUBST([GNULIB_WCSCSPN]) + GNULIB_WCSSPN=0; AC_SUBST([GNULIB_WCSSPN]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC]) HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT]) @@ -204,6 +205,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], HAVE_WCSCHR=1; AC_SUBST([HAVE_WCSCHR]) HAVE_WCSRCHR=1; AC_SUBST([HAVE_WCSRCHR]) HAVE_WCSCSPN=1; AC_SUBST([HAVE_WCSCSPN]) + HAVE_WCSSPN=1; AC_SUBST([HAVE_WCSSPN]) 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]) diff --git a/m4/wcsspn.m4 b/m4/wcsspn.m4 new file mode 100644 index 000000000..1225adcf9 --- /dev/null +++ b/m4/wcsspn.m4 @@ -0,0 +1,15 @@ +# wcsspn.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_WCSSPN], +[ + AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) + AC_CHECK_FUNCS_ONCE([wcsspn]) + if test $ac_cv_func_wcsspn = no; then + HAVE_WCSSPN=0 + AC_LIBOBJ([wcsspn]) + fi +]) diff --git a/modules/wchar b/modules/wchar index e049b6b16..9481e665f 100644 --- a/modules/wchar +++ b/modules/wchar @@ -64,6 +64,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''GNULIB_WCSCHR''@|$(GNULIB_WCSCHR)|g' \ -e 's|@''GNULIB_WCSRCHR''@|$(GNULIB_WCSRCHR)|g' \ -e 's|@''GNULIB_WCSCSPN''@|$(GNULIB_WCSCSPN)|g' \ + -e 's|@''GNULIB_WCSSPN''@|$(GNULIB_WCSSPN)|g' \ -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \ -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \ -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \ @@ -97,6 +98,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''HAVE_WCSCHR''@|$(HAVE_WCSCHR)|g' \ -e 's|@''HAVE_WCSRCHR''@|$(HAVE_WCSRCHR)|g' \ -e 's|@''HAVE_WCSCSPN''@|$(HAVE_WCSCSPN)|g' \ + -e 's|@''HAVE_WCSSPN''@|$(HAVE_WCSSPN)|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' \ diff --git a/modules/wcsspn b/modules/wcsspn new file mode 100644 index 000000000..3ecd53b97 --- /dev/null +++ b/modules/wcsspn @@ -0,0 +1,32 @@ +Description: +wcsspn() function: advance in a wide string, skipping any of a set of wide characters. + +Status: +obsolete + +Notice: +This module is obsolete. + +Files: +lib/wcsspn.c +lib/wcsspn-impl.h +m4/wcsspn.m4 + +Depends-on: +wchar +wcschr + +configure.ac: +gl_FUNC_WCSSPN +gl_WCHAR_MODULE_INDICATOR([wcsspn]) + +Makefile.am: + +Include: + + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/tests/test-wchar-c++.cc b/tests/test-wchar-c++.cc index 13371dd8f..b3e18ff95 100644 --- a/tests/test-wchar-c++.cc +++ b/tests/test-wchar-c++.cc @@ -187,6 +187,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::wcscspn, size_t, (const wchar_t *, const wchar_t *)); #endif +#if GNULIB_TEST_WCSSPN +SIGNATURE_CHECK (GNULIB_NAMESPACE::wcsspn, size_t, + (const wchar_t *, const wchar_t *)); +#endif + int main ()