changeset 14298:f0c82d0c08e6

New module 'wcscspn'. * modules/wcscspn: New file. * lib/wchar.in.h (wcscspn): New declaration. * lib/wcscspn.c: New file. * lib/wcscspn-impl.h: New file, from libutf8 with modifications. * m4/wcscspn.m4: New file. * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcscspn is declared. (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSCSPN, HAVE_WCSCSPN. * modules/wchar (Makefile.am): Substitute GNULIB_WCSCSPN, HAVE_WCSCSPN. * tests/test-wchar-c++.cc: Test the declaration of wcscspn. * doc/posix-functions/wcscspn.texi: Mention the new module.
author Bruno Haible <bruno@clisp.org>
date Sun, 06 Feb 2011 14:10:45 +0100
parents 029111e5ac51
children 0d372bfa8a0f
files ChangeLog doc/posix-functions/wcscspn.texi lib/wchar.in.h lib/wcscspn-impl.h lib/wcscspn.c m4/wchar_h.m4 m4/wcscspn.m4 modules/wchar modules/wcscspn tests/test-wchar-c++.cc
diffstat 10 files changed, 163 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-02-06  Bruno Haible  <bruno@clisp.org>
+
+	New module 'wcscspn'.
+	* modules/wcscspn: New file.
+	* lib/wchar.in.h (wcscspn): New declaration.
+	* lib/wcscspn.c: New file.
+	* lib/wcscspn-impl.h: New file, from libutf8 with modifications.
+	* m4/wcscspn.m4: New file.
+	* m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcscspn is declared.
+	(gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSCSPN, HAVE_WCSCSPN.
+	* modules/wchar (Makefile.am): Substitute GNULIB_WCSCSPN, HAVE_WCSCSPN.
+	* tests/test-wchar-c++.cc: Test the declaration of wcscspn.
+	* doc/posix-functions/wcscspn.texi: Mention the new module.
+
 2011-02-06  Bruno Haible  <bruno@clisp.org>
 
 	New module 'wcsrchr'.
--- a/doc/posix-functions/wcscspn.texi
+++ b/doc/posix-functions/wcscspn.texi
@@ -4,18 +4,18 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcscspn.html}
 
-Gnulib module: ---
+Gnulib module: wcscspn
 
 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
@@ -803,6 +803,23 @@
 #endif
 
 
+/* Return the length of the initial segmet of WCS which consists entirely
+   of wide characters not in REJECT.  */
+#if @GNULIB_WCSCSPN@
+# if !@HAVE_WCSCSPN@
+_GL_FUNCDECL_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t *reject));
+# endif
+_GL_CXXALIAS_SYS (wcscspn, size_t, (const wchar_t *wcs, const wchar_t *reject));
+_GL_CXXALIASWARN (wcscspn);
+#elif defined GNULIB_POSIXCHECK
+# undef wcscspn
+# if HAVE_RAW_DECL_WCSCSPN
+_GL_WARN_ON_USE (wcscspn, "wcscspn is unportable - "
+                 "use gnulib module wcscspn for portability");
+# endif
+#endif
+
+
 #endif /* _GL_WCHAR_H */
 #endif /* _GL_WCHAR_H */
 #endif
new file mode 100644
--- /dev/null
+++ b/lib/wcscspn-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/>.  */
+
+size_t
+wcscspn (const wchar_t *wcs, const wchar_t *reject)
+{
+  /* Optimize two cases.  */
+  if (reject[0] == (wchar_t)'\0')
+    return wcslen (wcs);
+
+  if (reject[1] == (wchar_t)'\0')
+    {
+      wchar_t wc = reject[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 (reject, *ptr))
+          break;
+      }
+    return ptr - wcs;
+  }
+}
new file mode 100644
--- /dev/null
+++ b/lib/wcscspn.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 "wcscspn-impl.h"
--- a/m4/wchar_h.m4
+++ b/m4/wchar_h.m4
@@ -53,6 +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
     ])
 ])
 
@@ -169,6 +170,7 @@
   GNULIB_WCSDUP=0;      AC_SUBST([GNULIB_WCSDUP])
   GNULIB_WCSCHR=0;      AC_SUBST([GNULIB_WCSCHR])
   GNULIB_WCSRCHR=0;     AC_SUBST([GNULIB_WCSRCHR])
+  GNULIB_WCSCSPN=0;     AC_SUBST([GNULIB_WCSCSPN])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_BTOWC=1;         AC_SUBST([HAVE_BTOWC])
   HAVE_MBSINIT=1;       AC_SUBST([HAVE_MBSINIT])
@@ -201,6 +203,7 @@
   HAVE_WCSDUP=1;        AC_SUBST([HAVE_WCSDUP])
   HAVE_WCSCHR=1;        AC_SUBST([HAVE_WCSCHR])
   HAVE_WCSRCHR=1;       AC_SUBST([HAVE_WCSRCHR])
+  HAVE_WCSCSPN=1;       AC_SUBST([HAVE_WCSCSPN])
   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/wcscspn.m4
@@ -0,0 +1,15 @@
+# wcscspn.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_WCSCSPN],
+[
+  AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+  AC_CHECK_FUNCS_ONCE([wcscspn])
+  if test $ac_cv_func_wcscspn = no; then
+    HAVE_WCSCSPN=0
+    AC_LIBOBJ([wcscspn])
+  fi
+])
--- a/modules/wchar
+++ b/modules/wchar
@@ -63,6 +63,7 @@
 	      -e 's|@''GNULIB_WCSDUP''@|$(GNULIB_WCSDUP)|g' \
 	      -e 's|@''GNULIB_WCSCHR''@|$(GNULIB_WCSCHR)|g' \
 	      -e 's|@''GNULIB_WCSRCHR''@|$(GNULIB_WCSRCHR)|g' \
+	      -e 's|@''GNULIB_WCSCSPN''@|$(GNULIB_WCSCSPN)|g' \
 	      -e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
 	      -e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \
 	      -e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \
@@ -95,6 +96,7 @@
 	      -e 's|@''HAVE_WCSDUP''@|$(HAVE_WCSDUP)|g' \
 	      -e 's|@''HAVE_WCSCHR''@|$(HAVE_WCSCHR)|g' \
 	      -e 's|@''HAVE_WCSRCHR''@|$(HAVE_WCSRCHR)|g' \
+	      -e 's|@''HAVE_WCSCSPN''@|$(HAVE_WCSCSPN)|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/wcscspn
@@ -0,0 +1,33 @@
+Description:
+wcscspn() function: search a wide string for any of a set of wide characters.
+
+Status:
+obsolete
+
+Notice:
+This module is obsolete.
+
+Files:
+lib/wcscspn.c
+lib/wcscspn-impl.h
+m4/wcscspn.m4
+
+Depends-on:
+wchar
+wcslen
+wcschr
+
+configure.ac:
+gl_FUNC_WCSCSPN
+gl_WCHAR_MODULE_INDICATOR([wcscspn])
+
+Makefile.am:
+
+Include:
+<wchar.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
--- a/tests/test-wchar-c++.cc
+++ b/tests/test-wchar-c++.cc
@@ -182,6 +182,11 @@
                  (const wchar_t *, wchar_t));
 #endif
 
+#if GNULIB_TEST_WCSCSPN
+SIGNATURE_CHECK (GNULIB_NAMESPACE::wcscspn, size_t,
+                 (const wchar_t *, const wchar_t *));
+#endif
+
 
 int
 main ()