# HG changeset patch # User Bruno Haible # Date 1296991531 -3600 # Node ID ba9661869ddae71650fa037bd5a2805dea97a4b3 # Parent 517e0af1a79b6b9cde82026265b8c71043379991 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. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2011-02-06 Bruno Haible + + 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 New module 'wcscasecmp'. diff --git a/doc/posix-functions/wcsncasecmp.texi b/doc/posix-functions/wcsncasecmp.texi --- 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 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -702,6 +702,24 @@ #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 --- /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 , 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 . */ + +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 --- /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 , 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 + +#include "wcsncasecmp-impl.h" diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4 --- a/m4/wchar_h.m4 +++ b/m4/wchar_h.m4 @@ -52,7 +52,7 @@ [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_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 @@ 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 --- /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 --- a/modules/wchar +++ b/modules/wchar @@ -57,6 +57,7 @@ -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 @@ -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 --- /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: + + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/tests/test-wchar-c++.cc b/tests/test-wchar-c++.cc --- a/tests/test-wchar-c++.cc +++ b/tests/test-wchar-c++.cc @@ -153,6 +153,11 @@ (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 ()