summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--doc/posix-functions/wcsstr.texi8
-rw-r--r--lib/wchar.in.h18
-rw-r--r--lib/wcsstr-impl.h51
-rw-r--r--lib/wcsstr.c23
-rw-r--r--m4/wchar_h.m44
-rw-r--r--m4/wcsstr.m415
-rw-r--r--modules/wchar2
-rw-r--r--modules/wcsstr26
-rw-r--r--tests/test-wchar-c++.cc5
10 files changed, 161 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 5d6be99ce7..23694c5e01 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2011-02-06 Bruno Haible <bruno@clisp.org>
+ New module 'wcsstr'.
+ * modules/wcsstr: New file.
+ * lib/wchar.in.h (wcsstr): New declaration.
+ * lib/wcsstr.c: New file.
+ * lib/wcsstr-impl.h: New file, from libutf8 with modifications.
+ * m4/wcsstr.m4: New file.
+ * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcsstr is declared.
+ (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSSTR, HAVE_WCSSTR.
+ * modules/wchar (Makefile.am): Substitute GNULIB_WCSSTR, HAVE_WCSSTR.
+ * tests/test-wchar-c++.cc: Test the declaration of wcsstr.
+ * doc/posix-functions/wcsstr.texi: Mention the new module.
+
+2011-02-06 Bruno Haible <bruno@clisp.org>
+
New module 'wcspbrk'.
* modules/wcspbrk: New file.
* lib/wchar.in.h (wcspbrk): New declaration.
diff --git a/doc/posix-functions/wcsstr.texi b/doc/posix-functions/wcsstr.texi
index 7c004958dd..e01daaf699 100644
--- a/doc/posix-functions/wcsstr.texi
+++ b/doc/posix-functions/wcsstr.texi
@@ -4,18 +4,18 @@
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcsstr.html}
-Gnulib module: ---
+Gnulib module: wcsstr
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+HP-UX 11.00, IRIX 5.3, Solaris 2.6.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
@item
-This function is missing on some platforms:
-HP-UX 11.00, IRIX 5.3, Solaris 2.6.
-@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 3d286e3281..b175ab7ec5 100644
--- a/lib/wchar.in.h
+++ b/lib/wchar.in.h
@@ -855,6 +855,24 @@ _GL_WARN_ON_USE (wcspbrk, "wcspbrk is unportable - "
#endif
+/* Find the first occurrence of NEEDLE in HAYSTACK. */
+#if @GNULIB_WCSSTR@
+# if !@HAVE_WCSSTR@
+_GL_FUNCDECL_SYS (wcsstr, wchar_t *,
+ (const wchar_t *haystack, const wchar_t *needle));
+# endif
+_GL_CXXALIAS_SYS (wcsstr, wchar_t *,
+ (const wchar_t *haystack, const wchar_t *needle));
+_GL_CXXALIASWARN (wcsstr);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsstr
+# if HAVE_RAW_DECL_WCSSTR
+_GL_WARN_ON_USE (wcsstr, "wcsstr is unportable - "
+ "use gnulib module wcsstr for portability");
+# endif
+#endif
+
+
#endif /* _GL_WCHAR_H */
#endif /* _GL_WCHAR_H */
#endif
diff --git a/lib/wcsstr-impl.h b/lib/wcsstr-impl.h
new file mode 100644
index 0000000000..f3fb3fb967
--- /dev/null
+++ b/lib/wcsstr-impl.h
@@ -0,0 +1,51 @@
+/* Locate a substring in a 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/>. */
+
+wchar_t *
+wcsstr (const wchar_t *haystack, const wchar_t *needle)
+{
+ wchar_t n = needle[0];
+
+ /* Is needle empty? */
+ if (n == (wchar_t)'\0')
+ return (wchar_t *) haystack;
+
+ /* Is needle nearly empty? */
+ if (needle[1] == (wchar_t)'\0')
+ return wcschr (haystack, n);
+
+ /* Search for needle's first character. */
+ for (; *haystack != (wchar_t)'\0'; haystack++)
+ {
+ if (*haystack == n)
+ {
+ /* Compare with needle's remaining characters. */
+ const wchar_t *hptr = haystack + 1;
+ const wchar_t *nptr = needle + 1;
+ for (;;)
+ {
+ if (*hptr != *nptr)
+ break;
+ hptr++; nptr++;
+ if (*nptr == (wchar_t)'\0')
+ return (wchar_t *) haystack;
+ }
+ }
+ }
+
+ return NULL;
+}
diff --git a/lib/wcsstr.c b/lib/wcsstr.c
new file mode 100644
index 0000000000..3a63447a36
--- /dev/null
+++ b/lib/wcsstr.c
@@ -0,0 +1,23 @@
+/* Locate a substring in a 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 "wcsstr-impl.h"
diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4
index 8b54006da6..9e5fbcdd5e 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 wcsspn wcspbrk
+ wcscspn wcsspn wcspbrk wcsstr
])
])
@@ -173,6 +173,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
GNULIB_WCSCSPN=0; AC_SUBST([GNULIB_WCSCSPN])
GNULIB_WCSSPN=0; AC_SUBST([GNULIB_WCSSPN])
GNULIB_WCSPBRK=0; AC_SUBST([GNULIB_WCSPBRK])
+ GNULIB_WCSSTR=0; AC_SUBST([GNULIB_WCSSTR])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC])
HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT])
@@ -208,6 +209,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
HAVE_WCSCSPN=1; AC_SUBST([HAVE_WCSCSPN])
HAVE_WCSSPN=1; AC_SUBST([HAVE_WCSSPN])
HAVE_WCSPBRK=1; AC_SUBST([HAVE_WCSPBRK])
+ HAVE_WCSSTR=1; AC_SUBST([HAVE_WCSSTR])
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/wcsstr.m4 b/m4/wcsstr.m4
new file mode 100644
index 0000000000..3ac2caf448
--- /dev/null
+++ b/m4/wcsstr.m4
@@ -0,0 +1,15 @@
+# wcsstr.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_WCSSTR],
+[
+ AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+ AC_CHECK_FUNCS_ONCE([wcsstr])
+ if test $ac_cv_func_wcsstr = no; then
+ HAVE_WCSSTR=0
+ AC_LIBOBJ([wcsstr])
+ fi
+])
diff --git a/modules/wchar b/modules/wchar
index 8852292e42..f2a4a0c373 100644
--- a/modules/wchar
+++ b/modules/wchar
@@ -66,6 +66,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''GNULIB_WCSCSPN''@|$(GNULIB_WCSCSPN)|g' \
-e 's|@''GNULIB_WCSSPN''@|$(GNULIB_WCSSPN)|g' \
-e 's|@''GNULIB_WCSPBRK''@|$(GNULIB_WCSPBRK)|g' \
+ -e 's|@''GNULIB_WCSSTR''@|$(GNULIB_WCSSTR)|g' \
-e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
-e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \
-e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \
@@ -101,6 +102,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''HAVE_WCSCSPN''@|$(HAVE_WCSCSPN)|g' \
-e 's|@''HAVE_WCSSPN''@|$(HAVE_WCSSPN)|g' \
-e 's|@''HAVE_WCSPBRK''@|$(HAVE_WCSPBRK)|g' \
+ -e 's|@''HAVE_WCSSTR''@|$(HAVE_WCSSTR)|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/wcsstr b/modules/wcsstr
new file mode 100644
index 0000000000..22a2fb763c
--- /dev/null
+++ b/modules/wcsstr
@@ -0,0 +1,26 @@
+Description:
+wcsstr() function: locate a substring in a wide string.
+
+Files:
+lib/wcsstr.c
+lib/wcsstr-impl.h
+m4/wcsstr.m4
+
+Depends-on:
+wchar
+wcschr
+
+configure.ac:
+gl_FUNC_WCSSTR
+gl_WCHAR_MODULE_INDICATOR([wcsstr])
+
+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 bac74ab588..495a6b45e3 100644
--- a/tests/test-wchar-c++.cc
+++ b/tests/test-wchar-c++.cc
@@ -197,6 +197,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::wcspbrk, wchar_t *,
(const wchar_t *, const wchar_t *));
#endif
+#if GNULIB_TEST_WCSSTR
+SIGNATURE_CHECK (GNULIB_NAMESPACE::wcsstr, wchar_t *,
+ (const wchar_t *, const wchar_t *));
+#endif
+
int
main ()