summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2011-02-06 14:02:26 +0100
committerBruno Haible <bruno@clisp.org>2011-02-07 23:36:06 +0100
commitf966b70bca56f1925c529598012eabb7d9fec5bf (patch)
tree4db1ac9c552b210041300b348d657ed911a16198
parent214aca197fc1b600e119e0fbae8cf196b48c5276 (diff)
downloadgnulib-f966b70bca56f1925c529598012eabb7d9fec5bf.tar.gz
New module 'wcsrchr'.
* modules/wcsrchr: New file. * lib/wchar.in.h (wcsrchr): New declaration. * lib/wcsrchr.c: New file. * lib/wcsrchr-impl.h: New file, from libutf8 with modifications. * m4/wcsrchr.m4: New file. * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcsrchr is declared. (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSRCHR, HAVE_WCSRCHR. * modules/wchar (Makefile.am): Substitute GNULIB_WCSRCHR, HAVE_WCSRCHR. * tests/test-wchar-c++.cc: Test the declaration of wcsrchr. * doc/posix-functions/wcsrchr.texi: Mention the new module.
-rw-r--r--ChangeLog14
-rw-r--r--doc/posix-functions/wcsrchr.texi8
-rw-r--r--lib/wchar.in.h16
-rw-r--r--lib/wcsrchr-impl.h33
-rw-r--r--lib/wcsrchr.c23
-rw-r--r--m4/wchar_h.m44
-rw-r--r--m4/wcsrchr.m415
-rw-r--r--modules/wchar2
-rw-r--r--modules/wcsrchr31
-rw-r--r--tests/test-wchar-c++.cc5
10 files changed, 146 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index b2875e9422..75391cc9c1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2011-02-06 Bruno Haible <bruno@clisp.org>
+ New module 'wcsrchr'.
+ * modules/wcsrchr: New file.
+ * lib/wchar.in.h (wcsrchr): New declaration.
+ * lib/wcsrchr.c: New file.
+ * lib/wcsrchr-impl.h: New file, from libutf8 with modifications.
+ * m4/wcsrchr.m4: New file.
+ * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcsrchr is declared.
+ (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSRCHR, HAVE_WCSRCHR.
+ * modules/wchar (Makefile.am): Substitute GNULIB_WCSRCHR, HAVE_WCSRCHR.
+ * tests/test-wchar-c++.cc: Test the declaration of wcsrchr.
+ * doc/posix-functions/wcsrchr.texi: Mention the new module.
+
+2011-02-06 Bruno Haible <bruno@clisp.org>
+
New module 'wcschr'.
* modules/wcschr: New file.
* lib/wchar.in.h (wcschr): New declaration.
diff --git a/doc/posix-functions/wcsrchr.texi b/doc/posix-functions/wcsrchr.texi
index cf4f122e3a..a052d19e37 100644
--- a/doc/posix-functions/wcsrchr.texi
+++ b/doc/posix-functions/wcsrchr.texi
@@ -4,18 +4,18 @@
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcsrchr.html}
-Gnulib module: ---
+Gnulib module: wcsrchr
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 815180f11e..8eaf4f63d6 100644
--- a/lib/wchar.in.h
+++ b/lib/wchar.in.h
@@ -787,6 +787,22 @@ _GL_WARN_ON_USE (wcschr, "wcschr is unportable - "
#endif
+/* Find the last occurrence of WC in WCS. */
+#if @GNULIB_WCSRCHR@
+# if !@HAVE_WCSRCHR@
+_GL_FUNCDECL_SYS (wcsrchr, wchar_t *, (const wchar_t *wcs, wchar_t wc));
+# endif
+_GL_CXXALIAS_SYS (wcsrchr, wchar_t *, (const wchar_t *wcs, wchar_t wc));
+_GL_CXXALIASWARN (wcsrchr);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsrchr
+# if HAVE_RAW_DECL_WCSRCHR
+_GL_WARN_ON_USE (wcsrchr, "wcsrchr is unportable - "
+ "use gnulib module wcsrchr for portability");
+# endif
+#endif
+
+
#endif /* _GL_WCHAR_H */
#endif /* _GL_WCHAR_H */
#endif
diff --git a/lib/wcsrchr-impl.h b/lib/wcsrchr-impl.h
new file mode 100644
index 0000000000..db3ba0663d
--- /dev/null
+++ b/lib/wcsrchr-impl.h
@@ -0,0 +1,33 @@
+/* Search wide string for a wide character.
+ 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 *
+wcsrchr (const wchar_t *wcs, wchar_t wc)
+{
+ /* Calling wcslen and then searching from the other end would cause more
+ memory accesses. Avoid that, at the cost of a few more comparisons. */
+ wchar_t *result = NULL;
+
+ for (;; wcs++)
+ {
+ if (*wcs == wc)
+ result = (wchar_t *) wcs;
+ if (*wcs == (wchar_t)'\0')
+ break;
+ }
+ return result;
+}
diff --git a/lib/wcsrchr.c b/lib/wcsrchr.c
new file mode 100644
index 0000000000..a717801741
--- /dev/null
+++ b/lib/wcsrchr.c
@@ -0,0 +1,23 @@
+/* Search wide string for a wide character.
+ 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 "wcsrchr-impl.h"
diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4
index bbc124a685..2dbbb163b0 100644
--- a/m4/wchar_h.m4
+++ b/m4/wchar_h.m4
@@ -52,7 +52,7 @@ AC_DEFUN([gl_WCHAR_H],
[btowc wctob mbsinit mbrtowc mbrlen mbsrtowcs mbsnrtowcs wcrtomb
wcsrtombs wcsnrtombs wcwidth wmemchr wmemcmp wmemcpy wmemmove wmemset
wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat wcscmp
- wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr
+ wcsncmp wcscasecmp wcsncasecmp wcscoll wcsxfrm wcsdup wcschr wcsrchr
])
])
@@ -168,6 +168,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
GNULIB_WCSXFRM=0; AC_SUBST([GNULIB_WCSXFRM])
GNULIB_WCSDUP=0; AC_SUBST([GNULIB_WCSDUP])
GNULIB_WCSCHR=0; AC_SUBST([GNULIB_WCSCHR])
+ GNULIB_WCSRCHR=0; AC_SUBST([GNULIB_WCSRCHR])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC])
HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT])
@@ -199,6 +200,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
HAVE_WCSXFRM=1; AC_SUBST([HAVE_WCSXFRM])
HAVE_WCSDUP=1; AC_SUBST([HAVE_WCSDUP])
HAVE_WCSCHR=1; AC_SUBST([HAVE_WCSCHR])
+ HAVE_WCSRCHR=1; AC_SUBST([HAVE_WCSRCHR])
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/wcsrchr.m4 b/m4/wcsrchr.m4
new file mode 100644
index 0000000000..06c446ed50
--- /dev/null
+++ b/m4/wcsrchr.m4
@@ -0,0 +1,15 @@
+# wcsrchr.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_WCSRCHR],
+[
+ AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+ AC_CHECK_FUNCS_ONCE([wcsrchr])
+ if test $ac_cv_func_wcsrchr = no; then
+ HAVE_WCSRCHR=0
+ AC_LIBOBJ([wcsrchr])
+ fi
+])
diff --git a/modules/wchar b/modules/wchar
index 78d8c661a7..3a57d59b07 100644
--- a/modules/wchar
+++ b/modules/wchar
@@ -62,6 +62,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''GNULIB_WCSXFRM''@|$(GNULIB_WCSXFRM)|g' \
-e 's|@''GNULIB_WCSDUP''@|$(GNULIB_WCSDUP)|g' \
-e 's|@''GNULIB_WCSCHR''@|$(GNULIB_WCSCHR)|g' \
+ -e 's|@''GNULIB_WCSRCHR''@|$(GNULIB_WCSRCHR)|g' \
-e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
-e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \
-e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \
@@ -93,6 +94,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''HAVE_WCSXFRM''@|$(HAVE_WCSXFRM)|g' \
-e 's|@''HAVE_WCSDUP''@|$(HAVE_WCSDUP)|g' \
-e 's|@''HAVE_WCSCHR''@|$(HAVE_WCSCHR)|g' \
+ -e 's|@''HAVE_WCSRCHR''@|$(HAVE_WCSRCHR)|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/wcsrchr b/modules/wcsrchr
new file mode 100644
index 0000000000..903abbad7a
--- /dev/null
+++ b/modules/wcsrchr
@@ -0,0 +1,31 @@
+Description:
+wcsrchr() function: search wide string for a wide character.
+
+Status:
+obsolete
+
+Notice:
+This module is obsolete.
+
+Files:
+lib/wcsrchr.c
+lib/wcsrchr-impl.h
+m4/wcsrchr.m4
+
+Depends-on:
+wchar
+
+configure.ac:
+gl_FUNC_WCSRCHR
+gl_WCHAR_MODULE_INDICATOR([wcsrchr])
+
+Makefile.am:
+
+Include:
+<wchar.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
diff --git a/tests/test-wchar-c++.cc b/tests/test-wchar-c++.cc
index 25583017bd..3342d05a11 100644
--- a/tests/test-wchar-c++.cc
+++ b/tests/test-wchar-c++.cc
@@ -177,6 +177,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::wcschr, wchar_t *,
(const wchar_t *, wchar_t));
#endif
+#if GNULIB_TEST_WCSRCHR
+SIGNATURE_CHECK (GNULIB_NAMESPACE::wcsrchr, wchar_t *,
+ (const wchar_t *, wchar_t));
+#endif
+
int
main ()