summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2011-02-06 12:25:31 +0100
committerBruno Haible <bruno@clisp.org>2011-02-07 23:36:05 +0100
commite1cc6ea006da8ff4527e055e7aa2db0d69351a05 (patch)
treea3d51024cb1a84d9da95be91626c434ba4004168
parent98b6cac347783a047671e9a9235933dddd9e5aa8 (diff)
downloadgnulib-e1cc6ea006da8ff4527e055e7aa2db0d69351a05.tar.gz
New module 'wcsncasecmp'.
* modules/wcsncasecmp: New file. * lib/wchar.in.h (wcsncasecmp): New declaration. * lib/wcsncasecmp.c: New file. * lib/wcsncasecmp-impl.h: New file, from libutf8 with modifications. * m4/wcsncasecmp.m4: New file. * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcsncasecmp is declared. (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSNCASECMP, HAVE_WCSNCASECMP. * modules/wchar (Makefile.am): Substitute GNULIB_WCSNCASECMP, HAVE_WCSNCASECMP. * tests/test-wchar-c++.cc: Test the declaration of wcsncasecmp. * doc/posix-functions/wcsncasecmp.texi: Mention the new module.
-rw-r--r--ChangeLog15
-rw-r--r--doc/posix-functions/wcsncasecmp.texi10
-rw-r--r--lib/wchar.in.h18
-rw-r--r--lib/wcsncasecmp-impl.h36
-rw-r--r--lib/wcsncasecmp.c25
-rw-r--r--m4/wchar_h.m458
-rw-r--r--m4/wcsncasecmp.m415
-rw-r--r--modules/wchar2
-rw-r--r--modules/wcsncasecmp26
-rw-r--r--tests/test-wchar-c++.cc5
10 files changed, 177 insertions, 33 deletions
diff --git a/ChangeLog b/ChangeLog
index e58831532c..168ba0f6b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2011-02-06 Bruno Haible <bruno@clisp.org>
+ New module 'wcsncasecmp'.
+ * modules/wcsncasecmp: New file.
+ * lib/wchar.in.h (wcsncasecmp): New declaration.
+ * lib/wcsncasecmp.c: New file.
+ * lib/wcsncasecmp-impl.h: New file, from libutf8 with modifications.
+ * m4/wcsncasecmp.m4: New file.
+ * m4/wchar_h.m4 (gl_WCHAR_H): Test whether wcsncasecmp is declared.
+ (gl_WCHAR_H_DEFAULTS): Initialize GNULIB_WCSNCASECMP, HAVE_WCSNCASECMP.
+ * modules/wchar (Makefile.am): Substitute GNULIB_WCSNCASECMP,
+ HAVE_WCSNCASECMP.
+ * tests/test-wchar-c++.cc: Test the declaration of wcsncasecmp.
+ * doc/posix-functions/wcsncasecmp.texi: Mention the new module.
+
+2011-02-06 Bruno Haible <bruno@clisp.org>
+
New module 'wcscasecmp'.
* modules/wcscasecmp: New file.
* lib/wchar.in.h (wcscasecmp): New declaration.
diff --git a/doc/posix-functions/wcsncasecmp.texi b/doc/posix-functions/wcsncasecmp.texi
index cfc5f76f8f..0c841b5e78 100644
--- a/doc/posix-functions/wcsncasecmp.texi
+++ b/doc/posix-functions/wcsncasecmp.texi
@@ -4,19 +4,19 @@
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/wcsncasecmp.html}
-Gnulib module: ---
+Gnulib module: wcsncasecmp
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on some platforms:
+MacOS X 10.5, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 4.3.2, HP-UX 11,
+IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x, mingw, BeOS.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
@item
-This function is missing on some platforms:
-MacOS X 10.5, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 4.3.2, HP-UX
-11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x, mingw, BeOS.
-@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 d9d023aabd..43a54d5ef9 100644
--- a/lib/wchar.in.h
+++ b/lib/wchar.in.h
@@ -702,6 +702,24 @@ _GL_WARN_ON_USE (wcscasecmp, "wcscasecmp is unportable - "
#endif
+/* Compare no more than N chars of S1 and S2, ignoring case. */
+#if @GNULIB_WCSNCASECMP@
+# if !@HAVE_WCSNCASECMP@
+_GL_FUNCDECL_SYS (wcsncasecmp, int,
+ (const wchar_t *s1, const wchar_t *s2, size_t n));
+# endif
+_GL_CXXALIAS_SYS (wcsncasecmp, int,
+ (const wchar_t *s1, const wchar_t *s2, size_t n));
+_GL_CXXALIASWARN (wcsncasecmp);
+#elif defined GNULIB_POSIXCHECK
+# undef wcsncasecmp
+# if HAVE_RAW_DECL_WCSNCASECMP
+_GL_WARN_ON_USE (wcsncasecmp, "wcsncasecmp is unportable - "
+ "use gnulib module wcsncasecmp for portability");
+# endif
+#endif
+
+
#endif /* _GL_WCHAR_H */
#endif /* _GL_WCHAR_H */
#endif
diff --git a/lib/wcsncasecmp-impl.h b/lib/wcsncasecmp-impl.h
new file mode 100644
index 0000000000..234f27a770
--- /dev/null
+++ b/lib/wcsncasecmp-impl.h
@@ -0,0 +1,36 @@
+/* Compare two wide strings ignoring case.
+ Copyright (C) 1999, 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/>. */
+
+int
+wcsncasecmp (const wchar_t *s1, const wchar_t *s2, size_t n)
+{
+ for (; n > 0;)
+ {
+ wchar_t wc1 = towlower (*s1++);
+ wchar_t wc2 = towlower (*s2++);
+ if (wc1 != (wchar_t)'\0' && wc1 == wc2)
+ {
+ n--;
+ continue;
+ }
+ /* Note that wc1 and wc2 each have at most 31 bits. */
+ return (int)wc1 - (int)wc2;
+ /* > 0 if wc1 > wc2, < 0 if wc1 < wc2,
+ = 0 if wc1 and wc2 are both '\0'. */
+ }
+ return 0;
+}
diff --git a/lib/wcsncasecmp.c b/lib/wcsncasecmp.c
new file mode 100644
index 0000000000..d2fafdd23f
--- /dev/null
+++ b/lib/wcsncasecmp.c
@@ -0,0 +1,25 @@
+/* Compare two wide strings ignoring case.
+ 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 <wctype.h>
+
+#include "wcsncasecmp-impl.h"
diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4
index 578134c234..a06c0a4139 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
+ wcsncmp wcscasecmp wcsncasecmp
])
])
@@ -136,33 +136,34 @@ AC_DEFUN([gl_WCHAR_MODULE_INDICATOR],
AC_DEFUN([gl_WCHAR_H_DEFAULTS],
[
- GNULIB_BTOWC=0; AC_SUBST([GNULIB_BTOWC])
- GNULIB_WCTOB=0; AC_SUBST([GNULIB_WCTOB])
- GNULIB_MBSINIT=0; AC_SUBST([GNULIB_MBSINIT])
- GNULIB_MBRTOWC=0; AC_SUBST([GNULIB_MBRTOWC])
- GNULIB_MBRLEN=0; AC_SUBST([GNULIB_MBRLEN])
- GNULIB_MBSRTOWCS=0; AC_SUBST([GNULIB_MBSRTOWCS])
- GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
- GNULIB_WCRTOMB=0; AC_SUBST([GNULIB_WCRTOMB])
- GNULIB_WCSRTOMBS=0; AC_SUBST([GNULIB_WCSRTOMBS])
- GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
- GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH])
- GNULIB_WMEMCHR=0; AC_SUBST([GNULIB_WMEMCHR])
- GNULIB_WMEMCMP=0; AC_SUBST([GNULIB_WMEMCMP])
- GNULIB_WMEMCPY=0; AC_SUBST([GNULIB_WMEMCPY])
- GNULIB_WMEMMOVE=0; AC_SUBST([GNULIB_WMEMMOVE])
- GNULIB_WMEMSET=0; AC_SUBST([GNULIB_WMEMSET])
- GNULIB_WCSLEN=0; AC_SUBST([GNULIB_WCSLEN])
- GNULIB_WCSNLEN=0; AC_SUBST([GNULIB_WCSNLEN])
- GNULIB_WCSCPY=0; AC_SUBST([GNULIB_WCSCPY])
- GNULIB_WCPCPY=0; AC_SUBST([GNULIB_WCPCPY])
- GNULIB_WCSNCPY=0; AC_SUBST([GNULIB_WCSNCPY])
- GNULIB_WCPNCPY=0; AC_SUBST([GNULIB_WCPNCPY])
- GNULIB_WCSCAT=0; AC_SUBST([GNULIB_WCSCAT])
- GNULIB_WCSNCAT=0; AC_SUBST([GNULIB_WCSNCAT])
- GNULIB_WCSCMP=0; AC_SUBST([GNULIB_WCSCMP])
- GNULIB_WCSNCMP=0; AC_SUBST([GNULIB_WCSNCMP])
- GNULIB_WCSCASECMP=0; AC_SUBST([GNULIB_WCSCASECMP])
+ GNULIB_BTOWC=0; AC_SUBST([GNULIB_BTOWC])
+ GNULIB_WCTOB=0; AC_SUBST([GNULIB_WCTOB])
+ GNULIB_MBSINIT=0; AC_SUBST([GNULIB_MBSINIT])
+ GNULIB_MBRTOWC=0; AC_SUBST([GNULIB_MBRTOWC])
+ GNULIB_MBRLEN=0; AC_SUBST([GNULIB_MBRLEN])
+ GNULIB_MBSRTOWCS=0; AC_SUBST([GNULIB_MBSRTOWCS])
+ GNULIB_MBSNRTOWCS=0; AC_SUBST([GNULIB_MBSNRTOWCS])
+ GNULIB_WCRTOMB=0; AC_SUBST([GNULIB_WCRTOMB])
+ GNULIB_WCSRTOMBS=0; AC_SUBST([GNULIB_WCSRTOMBS])
+ GNULIB_WCSNRTOMBS=0; AC_SUBST([GNULIB_WCSNRTOMBS])
+ GNULIB_WCWIDTH=0; AC_SUBST([GNULIB_WCWIDTH])
+ GNULIB_WMEMCHR=0; AC_SUBST([GNULIB_WMEMCHR])
+ GNULIB_WMEMCMP=0; AC_SUBST([GNULIB_WMEMCMP])
+ GNULIB_WMEMCPY=0; AC_SUBST([GNULIB_WMEMCPY])
+ GNULIB_WMEMMOVE=0; AC_SUBST([GNULIB_WMEMMOVE])
+ GNULIB_WMEMSET=0; AC_SUBST([GNULIB_WMEMSET])
+ GNULIB_WCSLEN=0; AC_SUBST([GNULIB_WCSLEN])
+ GNULIB_WCSNLEN=0; AC_SUBST([GNULIB_WCSNLEN])
+ GNULIB_WCSCPY=0; AC_SUBST([GNULIB_WCSCPY])
+ GNULIB_WCPCPY=0; AC_SUBST([GNULIB_WCPCPY])
+ GNULIB_WCSNCPY=0; AC_SUBST([GNULIB_WCSNCPY])
+ GNULIB_WCPNCPY=0; AC_SUBST([GNULIB_WCPNCPY])
+ GNULIB_WCSCAT=0; AC_SUBST([GNULIB_WCSCAT])
+ GNULIB_WCSNCAT=0; AC_SUBST([GNULIB_WCSNCAT])
+ GNULIB_WCSCMP=0; AC_SUBST([GNULIB_WCSCMP])
+ GNULIB_WCSNCMP=0; AC_SUBST([GNULIB_WCSNCMP])
+ GNULIB_WCSCASECMP=0; AC_SUBST([GNULIB_WCSCASECMP])
+ GNULIB_WCSNCASECMP=0; AC_SUBST([GNULIB_WCSNCASECMP])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_BTOWC=1; AC_SUBST([HAVE_BTOWC])
HAVE_MBSINIT=1; AC_SUBST([HAVE_MBSINIT])
@@ -189,6 +190,7 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS],
HAVE_WCSCMP=1; AC_SUBST([HAVE_WCSCMP])
HAVE_WCSNCMP=1; AC_SUBST([HAVE_WCSNCMP])
HAVE_WCSCASECMP=1; AC_SUBST([HAVE_WCSCASECMP])
+ HAVE_WCSNCASECMP=1; AC_SUBST([HAVE_WCSNCASECMP])
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/wcsncasecmp.m4 b/m4/wcsncasecmp.m4
new file mode 100644
index 0000000000..a7c468284e
--- /dev/null
+++ b/m4/wcsncasecmp.m4
@@ -0,0 +1,15 @@
+# wcsncasecmp.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_WCSNCASECMP],
+[
+ AC_REQUIRE([gl_WCHAR_H_DEFAULTS])
+ AC_CHECK_FUNCS_ONCE([wcsncasecmp])
+ if test $ac_cv_func_wcsncasecmp = no; then
+ HAVE_WCSNCASECMP=0
+ AC_LIBOBJ([wcsncasecmp])
+ fi
+])
diff --git a/modules/wchar b/modules/wchar
index 81861ce9ce..de85535a09 100644
--- a/modules/wchar
+++ b/modules/wchar
@@ -57,6 +57,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''GNULIB_WCSCMP''@|$(GNULIB_WCSCMP)|g' \
-e 's|@''GNULIB_WCSNCMP''@|$(GNULIB_WCSNCMP)|g' \
-e 's|@''GNULIB_WCSCASECMP''@|$(GNULIB_WCSCASECMP)|g' \
+ -e 's|@''GNULIB_WCSNCASECMP''@|$(GNULIB_WCSNCASECMP)|g' \
-e 's|@''HAVE_WINT_T''@|$(HAVE_WINT_T)|g' \
-e 's|@''HAVE_BTOWC''@|$(HAVE_BTOWC)|g' \
-e 's|@''HAVE_MBSINIT''@|$(HAVE_MBSINIT)|g' \
@@ -83,6 +84,7 @@ wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''HAVE_WCSCMP''@|$(HAVE_WCSCMP)|g' \
-e 's|@''HAVE_WCSNCMP''@|$(HAVE_WCSNCMP)|g' \
-e 's|@''HAVE_WCSCASECMP''@|$(HAVE_WCSCASECMP)|g' \
+ -e 's|@''HAVE_WCSNCASECMP''@|$(HAVE_WCSNCASECMP)|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/wcsncasecmp b/modules/wcsncasecmp
new file mode 100644
index 0000000000..8f4e1ad4ae
--- /dev/null
+++ b/modules/wcsncasecmp
@@ -0,0 +1,26 @@
+Description:
+wcsncasecmp() function: compare two wide strings ignoring case.
+
+Files:
+lib/wcsncasecmp.c
+lib/wcsncasecmp-impl.h
+m4/wcsncasecmp.m4
+
+Depends-on:
+wchar
+wctype
+
+configure.ac:
+gl_FUNC_WCSNCASECMP
+gl_WCHAR_MODULE_INDICATOR([wcsncasecmp])
+
+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 58521353c2..842c28d80a 100644
--- a/tests/test-wchar-c++.cc
+++ b/tests/test-wchar-c++.cc
@@ -153,6 +153,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::wcscasecmp, int,
(const wchar_t *, const wchar_t *));
#endif
+#if GNULIB_TEST_WCSNCASECMP
+SIGNATURE_CHECK (GNULIB_NAMESPACE::wcsncasecmp, int,
+ (const wchar_t *, const wchar_t *, size_t));
+#endif
+
int
main ()