Like for the "digit" class, POSIX provides a way to the libc implementor to add non-ASCII characters to the "xdigit" character class. However, ISO C 99 section 7.25.2.1.12 takes that freedom away. The iswxdigit() function is not ISO C compliant on a number of platforms. This series of patches provides the workaround.
2020-01-25 Bruno Haible <br...@clisp.org> mbchar, wctype: Use the corrected iswxdigit function. * modules/mbchar (Depends-on): Add iswxdigit. * modules/wctype (Depends-on): Likewise. iswxdigit: Add tests. * tests/test-iswxdigit.c: New file. * tests/test-iswxdigit.sh: New file. * modules/iswxdigit-tests: New file. iswxdigit: New module. * m4/iswxdigit.m4: New file. * lib/wctype.in.h (iswxdigit): Potentially override. (iswxdigit, rpl_iswxdigit): Test REPLACE_ISWXDIGIT, not REPLACE_ISWCNTRL. Rely on ISO C compliant definition. * lib/iswxdigit.c: New file. * m4/wctype_h.m4 (gl_WCTYPE_H_DEFAULTS): Initialize GNULIB_ISWXDIGIT, REPLACE_ISWXDIGIT. * modules/wctype-h (Makefile.am): Substitute GNULIB_ISWXDIGIT, REPLACE_ISWXDIGIT. * modules/iswxdigit: New file. * doc/posix-functions/iswxdigit.texi: Mention the portability problem.
>From 756370637a184426d4834b47cd653fc7fee296f5 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 25 Jan 2020 21:17:51 +0100 Subject: [PATCH 1/3] iswxdigit: New module. * m4/iswxdigit.m4: New file. * lib/wctype.in.h (iswxdigit): Potentially override. (iswxdigit, rpl_iswxdigit): Test REPLACE_ISWXDIGIT, not REPLACE_ISWCNTRL. Rely on ISO C compliant definition. * lib/iswxdigit.c: New file. * m4/wctype_h.m4 (gl_WCTYPE_H_DEFAULTS): Initialize GNULIB_ISWXDIGIT, REPLACE_ISWXDIGIT. * modules/wctype-h (Makefile.am): Substitute GNULIB_ISWXDIGIT, REPLACE_ISWXDIGIT. * modules/iswxdigit: New file. * doc/posix-functions/iswxdigit.texi: Mention the portability problem. --- ChangeLog | 15 +++++ doc/posix-functions/iswxdigit.texi | 3 + lib/iswxdigit.c | 33 +++++++++++ lib/wctype.in.h | 19 ++++++- m4/iswxdigit.m4 | 113 +++++++++++++++++++++++++++++++++++++ m4/wctype_h.m4 | 4 +- modules/iswxdigit | 35 ++++++++++++ modules/wctype-h | 2 + 8 files changed, 220 insertions(+), 4 deletions(-) create mode 100644 lib/iswxdigit.c create mode 100644 m4/iswxdigit.m4 create mode 100644 modules/iswxdigit diff --git a/ChangeLog b/ChangeLog index c70358c..e6c875b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2020-01-25 Bruno Haible <br...@clisp.org> + iswxdigit: New module. + * m4/iswxdigit.m4: New file. + * lib/wctype.in.h (iswxdigit): Potentially override. + (iswxdigit, rpl_iswxdigit): Test REPLACE_ISWXDIGIT, not + REPLACE_ISWCNTRL. Rely on ISO C compliant definition. + * lib/iswxdigit.c: New file. + * m4/wctype_h.m4 (gl_WCTYPE_H_DEFAULTS): Initialize GNULIB_ISWXDIGIT, + REPLACE_ISWXDIGIT. + * modules/wctype-h (Makefile.am): Substitute GNULIB_ISWXDIGIT, + REPLACE_ISWXDIGIT. + * modules/iswxdigit: New file. + * doc/posix-functions/iswxdigit.texi: Mention the portability problem. + +2020-01-25 Bruno Haible <br...@clisp.org> + lseek: Fix the override to not undo the effects of AC_SYS_LARGEFILE. Reported by John Donoghue <john.david.donog...@gmail.com> in <https://lists.gnu.org/archive/html/bug-gnulib/2020-01/msg00146.html>. diff --git a/doc/posix-functions/iswxdigit.texi b/doc/posix-functions/iswxdigit.texi index bdce3b4..705c829 100644 --- a/doc/posix-functions/iswxdigit.texi +++ b/doc/posix-functions/iswxdigit.texi @@ -15,6 +15,9 @@ Minix 3.1.8. This function cannot be called from plain inline or extern inline functions on some platforms: OS X 10.8. +@item +This function is not ISO C 99 compliant on some platforms: +FreeBSD 12, NetBSD 8.0, Solaris 11.4, MSVC 14. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/iswxdigit.c b/lib/iswxdigit.c new file mode 100644 index 0000000..5c1c182 --- /dev/null +++ b/lib/iswxdigit.c @@ -0,0 +1,33 @@ +/* Test wide character for being a hexadecimal digit. + Copyright (C) 2020 Free Software Foundation, Inc. + + 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 2, 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 <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include <wctype.h> + +int +iswxdigit (wint_t wc) +{ + return ((wc >= '0' && wc <= '9') +#if 'A' == 0x41 && 'a' == 0x61 + /* Optimization, assuming ASCII */ + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F') +#else + || (wc >= 'A' && wc <= 'F') || (wc >= 'a' && wc <= 'f') +#endif + ); +} diff --git a/lib/wctype.in.h b/lib/wctype.in.h index 09dbb55..5d266d9 100644 --- a/lib/wctype.in.h +++ b/lib/wctype.in.h @@ -210,7 +210,10 @@ rpl_iswupper (wint_t wc) _GL_WCTYPE_INLINE int rpl_iswxdigit (wint_t wc) { - return ((wchar_t) wc == wc ? iswxdigit ((wchar_t) wc) : 0); + return ((wchar_t) wc == wc + ? (wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F') + : 0); } _GL_WCTYPE_INLINE wint_t @@ -428,7 +431,7 @@ iswupper } _GL_WCTYPE_INLINE int -# if @REPLACE_ISWCNTRL@ +# if @REPLACE_ISWXDIGIT@ rpl_iswxdigit # else iswxdigit @@ -488,6 +491,16 @@ _GL_FUNCDECL_RPL (iswdigit, int, (wint_t wc)); # endif # endif +# if @GNULIB_ISWXDIGIT@ +# if @REPLACE_ISWXDIGIT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef iswxdigit +# define iswxdigit rpl_iswxdigit +# endif +_GL_FUNCDECL_RPL (iswxdigit, int, (wint_t wc)); +# endif +# endif + # endif # if defined __MINGW32__ && !@GNULIB_OVERRIDES_WINT_T@ @@ -578,7 +591,7 @@ _GL_CXXALIAS_RPL (iswupper, int, (wint_t wc)); #else _GL_CXXALIAS_SYS (iswupper, int, (wint_t wc)); #endif -#if @REPLACE_ISWCNTRL@ +#if @REPLACE_ISWXDIGIT@ _GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc)); #else _GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc)); diff --git a/m4/iswxdigit.m4 b/m4/iswxdigit.m4 new file mode 100644 index 0000000..8219013 --- /dev/null +++ b/m4/iswxdigit.m4 @@ -0,0 +1,113 @@ +# iswxdigit.m4 serial 1 +dnl Copyright (C) 2020 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_ISWXDIGIT], +[ + AC_REQUIRE([gl_WCTYPE_H_DEFAULTS]) + AC_REQUIRE([gl_WCTYPE_H]) + AC_REQUIRE([gt_LOCALE_JA]) + AC_REQUIRE([gt_LOCALE_FR_UTF8]) + AC_REQUIRE([gt_LOCALE_ZH_CN]) + + if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then + dnl <wctype.h> redefines iswxdigit already. + REPLACE_ISWXDIGIT="$REPLACE_ISWCNTRL" + else + AC_CACHE_CHECK([whether iswxdigit is ISO C compliant], + [gl_cv_func_iswxdigit_works], + [ + dnl Initial guess, used when cross-compiling or when no suitable locale + dnl is present. +changequote(,)dnl + case "$host_os" in + # Guess no on FreeBSD, NetBSD, Solaris, native Windows. + freebsd* | dragonfly* | netbsd* | solaris* | mingw*) + gl_cv_func_iswxdigit_works="guessing no" ;; + # Guess yes otherwise. + *) gl_cv_func_iswxdigit_works="guessing yes" ;; + esac +changequote([,])dnl + if test $LOCALE_JA != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_ZH_CN != none; then + AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include <locale.h> +#include <stdlib.h> +#include <string.h> +/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before + <wchar.h>. + BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be + included before <wchar.h>. */ +#include <stddef.h> +#include <stdio.h> +#include <time.h> +#include <wchar.h> +#include <wctype.h> + +/* Returns the value of iswxdigit for the multibyte character s[0..n-1]. */ +static int +for_character (const char *s, size_t n) +{ + mbstate_t state; + wchar_t wc; + size_t ret; + + memset (&state, '\0', sizeof (mbstate_t)); + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, s, n, &state); + if (ret != n) + abort (); + + return iswxdigit (wc); +} + +int +main (int argc, char *argv[]) +{ + int is; + int result = 0; + + if (setlocale (LC_ALL, "$LOCALE_JA") != NULL) + { + /* This fails on NetBSD 8.0. */ + /* U+FF21 FULLWIDTH LATIN CAPITAL LETTER A */ + is = for_character ("\243\301", 2); + if (!(is == 0)) + result |= 1; + } + if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL) + { + /* This fails on FreeBSD 12. */ + /* U+0663 ARABIC-INDIC DIGIT THREE */ + is = for_character ("\331\243", 2); + if (!(is == 0)) + result |= 2; + /* This fails on MSVC 14. */ + /* U+FF21 FULLWIDTH LATIN CAPITAL LETTER A */ + is = for_character ("\357\274\241", 3); + if (!(is == 0)) + result |= 4; + } + if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL) + { + /* This fails on Solaris 10, Solaris 11.4. */ + /* U+FF11 FULLWIDTH DIGIT ONE */ + is = for_character ("\243\261", 2); + if (!(is == 0)) + result |= 8; + } + return result; +}]])], + [gl_cv_func_iswxdigit_works=yes], + [gl_cv_func_iswxdigit_works=no], + [:]) + fi + ]) + case "$gl_cv_func_iswxdigit_works" in + *yes) ;; + *) REPLACE_ISWXDIGIT=1 ;; + esac + fi +]) diff --git a/m4/wctype_h.m4 b/m4/wctype_h.m4 index 24bad38..5c844b6 100644 --- a/m4/wctype_h.m4 +++ b/m4/wctype_h.m4 @@ -1,4 +1,4 @@ -# wctype_h.m4 serial 23 +# wctype_h.m4 serial 24 dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it. @@ -205,6 +205,7 @@ AC_DEFUN([gl_WCTYPE_H_DEFAULTS], [ GNULIB_ISWBLANK=0; AC_SUBST([GNULIB_ISWBLANK]) GNULIB_ISWDIGIT=0; AC_SUBST([GNULIB_ISWDIGIT]) + GNULIB_ISWXDIGIT=0; AC_SUBST([GNULIB_ISWXDIGIT]) GNULIB_WCTYPE=0; AC_SUBST([GNULIB_WCTYPE]) GNULIB_ISWCTYPE=0; AC_SUBST([GNULIB_ISWCTYPE]) GNULIB_WCTRANS=0; AC_SUBST([GNULIB_WCTRANS]) @@ -215,4 +216,5 @@ AC_DEFUN([gl_WCTYPE_H_DEFAULTS], HAVE_WCTRANS_T=1; AC_SUBST([HAVE_WCTRANS_T]) REPLACE_ISWBLANK=0; AC_SUBST([REPLACE_ISWBLANK]) REPLACE_ISWDIGIT=0; AC_SUBST([REPLACE_ISWDIGIT]) + REPLACE_ISWXDIGIT=0; AC_SUBST([REPLACE_ISWXDIGIT]) ]) diff --git a/modules/iswxdigit b/modules/iswxdigit new file mode 100644 index 0000000..b25b31d --- /dev/null +++ b/modules/iswxdigit @@ -0,0 +1,35 @@ +Description: +iswxdigit() function: test wide character for being a hexadecimal digit. + +Files: +lib/iswxdigit.c +m4/iswxdigit.m4 +m4/locale-fr.m4 +m4/locale-ja.m4 +m4/locale-zh.m4 +m4/codeset.m4 + +Depends-on: +wctype-h + +configure.ac: +gl_FUNC_ISWXDIGIT +if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then + : +else + if test $REPLACE_ISWXDIGIT = 1; then + AC_LIBOBJ([iswxdigit]) + fi +fi +gl_WCTYPE_MODULE_INDICATOR([iswxdigit]) + +Makefile.am: + +Include: +<wctype.h> + +License: +LGPLv2+ + +Maintainer: +Bruno Haible diff --git a/modules/wctype-h b/modules/wctype-h index 58f4e51..b7aef46 100644 --- a/modules/wctype-h +++ b/modules/wctype-h @@ -35,6 +35,7 @@ wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H -e 's/@''GNULIB_OVERRIDES_WINT_T''@/$(GNULIB_OVERRIDES_WINT_T)/g' \ -e 's/@''GNULIB_ISWBLANK''@/$(GNULIB_ISWBLANK)/g' \ -e 's/@''GNULIB_ISWDIGIT''@/$(GNULIB_ISWDIGIT)/g' \ + -e 's/@''GNULIB_ISWXDIGIT''@/$(GNULIB_ISWXDIGIT)/g' \ -e 's/@''GNULIB_WCTYPE''@/$(GNULIB_WCTYPE)/g' \ -e 's/@''GNULIB_ISWCTYPE''@/$(GNULIB_ISWCTYPE)/g' \ -e 's/@''GNULIB_WCTRANS''@/$(GNULIB_WCTRANS)/g' \ @@ -46,6 +47,7 @@ wctype.h: wctype.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \ -e 's/@''REPLACE_ISWBLANK''@/$(REPLACE_ISWBLANK)/g' \ -e 's/@''REPLACE_ISWDIGIT''@/$(REPLACE_ISWDIGIT)/g' \ + -e 's/@''REPLACE_ISWXDIGIT''@/$(REPLACE_ISWXDIGIT)/g' \ -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \ -e 's/@''REPLACE_TOWLOWER''@/$(REPLACE_TOWLOWER)/g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -- 2.7.4
>From 111435dda09dbede56b68322dcc54689700d5109 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 25 Jan 2020 21:18:42 +0100 Subject: [PATCH 2/3] iswxdigit: Add tests. * tests/test-iswxdigit.c: New file. * tests/test-iswxdigit.sh: New file. * modules/iswxdigit-tests: New file. --- ChangeLog | 5 + modules/iswxdigit-tests | 29 ++++++ tests/test-iswxdigit.c | 259 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/test-iswxdigit.sh | 39 ++++++++ 4 files changed, 332 insertions(+) create mode 100644 modules/iswxdigit-tests create mode 100644 tests/test-iswxdigit.c create mode 100755 tests/test-iswxdigit.sh diff --git a/ChangeLog b/ChangeLog index e6c875b..f5a0863 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2020-01-25 Bruno Haible <br...@clisp.org> + iswxdigit: Add tests. + * tests/test-iswxdigit.c: New file. + * tests/test-iswxdigit.sh: New file. + * modules/iswxdigit-tests: New file. + iswxdigit: New module. * m4/iswxdigit.m4: New file. * lib/wctype.in.h (iswxdigit): Potentially override. diff --git a/modules/iswxdigit-tests b/modules/iswxdigit-tests new file mode 100644 index 0000000..425c51c --- /dev/null +++ b/modules/iswxdigit-tests @@ -0,0 +1,29 @@ +Files: +tests/test-iswxdigit.sh +tests/test-iswxdigit.c +tests/signature.h +tests/macros.h +m4/locale-fr.m4 +m4/locale-ja.m4 +m4/locale-zh.m4 +m4/codeset.m4 + +Depends-on: +mbrtowc +setlocale + +configure.ac: +gt_LOCALE_FR +gt_LOCALE_FR_UTF8 +gt_LOCALE_JA +gt_LOCALE_ZH_CN + +Makefile.am: +TESTS += test-iswxdigit.sh +TESTS_ENVIRONMENT += \ + LOCALE_FR='@LOCALE_FR@' \ + LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' \ + LOCALE_JA='@LOCALE_JA@' \ + LOCALE_ZH_CN='@LOCALE_ZH_CN@' +check_PROGRAMS += test-iswxdigit +test_iswxdigit_LDADD = $(LDADD) $(LIB_SETLOCALE) $(LIB_MBRTOWC) diff --git a/tests/test-iswxdigit.c b/tests/test-iswxdigit.c new file mode 100644 index 0000000..77aa0f0 --- /dev/null +++ b/tests/test-iswxdigit.c @@ -0,0 +1,259 @@ +/* Test of iswxdigit() function. + Copyright (C) 2020 Free Software Foundation, Inc. + + 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 <https://www.gnu.org/licenses/>. */ + +#include <config.h> + +#include <wctype.h> + +#include "signature.h" +SIGNATURE_CHECK (iswxdigit, int, (wint_t)); + +#include <locale.h> +#include <stdlib.h> +#include <string.h> +#include <wchar.h> + +#include "macros.h" + +/* Returns the value of iswxdigit for the multibyte character s[0..n-1]. */ +static int +for_character (const char *s, size_t n) +{ + mbstate_t state; + wchar_t wc; + size_t ret; + + memset (&state, '\0', sizeof (mbstate_t)); + wc = (wchar_t) 0xBADFACE; + ret = mbrtowc (&wc, s, n, &state); + if (ret == n) + return iswxdigit (wc); + else + return 0; +} + +int +main (int argc, char *argv[]) +{ + int is; + char buf[4]; + + /* configure should already have checked that the locale is supported. */ + if (setlocale (LC_ALL, "") == NULL) + return 1; + + /* Test WEOF. */ + is = iswxdigit (WEOF); + ASSERT (is == 0); + + /* Test single-byte characters. + ISO C 99 sections 7.25.2.1.12 and 6.4.4.1 specify that the hexadecimal + digits include only the ASCII 0 ... 9 A ... F a ... f characters. */ + { + int c; + + for (c = 0; c < 0x100; c++) + switch (c) + { + case '\t': case '\v': case '\f': + case ' ': case '!': case '"': case '#': case '%': + case '&': case '\'': case '(': case ')': case '*': + case '+': case ',': case '-': case '.': case '/': + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case ':': case ';': case '<': case '=': case '>': + case '?': + case 'A': case 'B': case 'C': case 'D': case 'E': + case 'F': case 'G': case 'H': case 'I': case 'J': + case 'K': case 'L': case 'M': case 'N': case 'O': + case 'P': case 'Q': case 'R': case 'S': case 'T': + case 'U': case 'V': case 'W': case 'X': case 'Y': + case 'Z': + case '[': case '\\': case ']': case '^': case '_': + case 'a': case 'b': case 'c': case 'd': case 'e': + case 'f': case 'g': case 'h': case 'i': case 'j': + case 'k': case 'l': case 'm': case 'n': case 'o': + case 'p': case 'q': case 'r': case 's': case 't': + case 'u': case 'v': case 'w': case 'x': case 'y': + case 'z': case '{': case '|': case '}': case '~': + /* c is in the ISO C "basic character set". */ + buf[0] = (unsigned char) c; + is = for_character (buf, 1); + switch (c) + { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + ASSERT (is != 0); + break; + default: + ASSERT (is == 0); + break; + } + break; + } + } + + if (argc > 1) + switch (argv[1][0]) + { + case '0': + /* C locale; tested above. */ + return 0; + + case '1': + /* Locale encoding is ISO-8859-1 or ISO-8859-15. */ + { + /* U+00B2 SUPERSCRIPT TWO */ + is = for_character ("\262", 1); + ASSERT (is == 0); + /* U+00B3 SUPERSCRIPT THREE */ + is = for_character ("\263", 1); + ASSERT (is == 0); + /* U+00B9 SUPERSCRIPT ONE */ + is = for_character ("\271", 1); + ASSERT (is == 0); + } + return 0; + + case '2': + /* Locale encoding is EUC-JP. */ + { + /* U+FF11 FULLWIDTH DIGIT ONE */ + is = for_character ("\243\261", 2); + ASSERT (is == 0); + /* U+FF21 FULLWIDTH LATIN CAPITAL LETTER A */ + is = for_character ("\243\301", 2); + ASSERT (is == 0); + /* U+FF41 FULLWIDTH LATIN SMALL LETTER A */ + is = for_character ("\243\341", 2); + ASSERT (is == 0); + } + return 0; + + case '3': + /* Locale encoding is UTF-8. */ + { + /* U+00B2 SUPERSCRIPT TWO */ + is = for_character ("\302\262", 2); + ASSERT (is == 0); + /* U+00B3 SUPERSCRIPT THREE */ + is = for_character ("\302\263", 2); + ASSERT (is == 0); + /* U+00B9 SUPERSCRIPT ONE */ + is = for_character ("\302\271", 2); + ASSERT (is == 0); + /* U+0663 ARABIC-INDIC DIGIT THREE */ + is = for_character ("\331\243", 2); + ASSERT (is == 0); + /* U+2070 SUPERSCRIPT ZERO */ + is = for_character ("\342\201\260", 3); + ASSERT (is == 0); + /* U+2079 SUPERSCRIPT NINE */ + is = for_character ("\342\201\271", 3); + ASSERT (is == 0); + /* U+FF11 FULLWIDTH DIGIT ONE */ + is = for_character ("\357\274\221", 3); + ASSERT (is == 0); + /* U+FF21 FULLWIDTH LATIN CAPITAL LETTER A */ + is = for_character ("\357\274\241", 3); + ASSERT (is == 0); + /* U+FF41 FULLWIDTH LATIN SMALL LETTER A */ + is = for_character ("\357\275\201", 3); + ASSERT (is == 0); + /* U+1D7D1 MATHEMATICAL BOLD DIGIT THREE */ + is = for_character ("\360\235\237\221", 4); + ASSERT (is == 0); + /* U+1D7DB MATHEMATICAL DOUBLE-STRUCK DIGIT THREE */ + is = for_character ("\360\235\237\233", 4); + ASSERT (is == 0); + /* U+1D7E5 MATHEMATICAL SANS-SERIF DIGIT THREE */ + is = for_character ("\360\235\237\245", 4); + ASSERT (is == 0); + /* U+1D7EF MATHEMATICAL SANS-SERIF BOLD DIGIT THREE */ + is = for_character ("\360\235\237\257", 4); + ASSERT (is == 0); + /* U+1D7F9 MATHEMATICAL MONOSPACE DIGIT THREE */ + is = for_character ("\360\235\237\271", 4); + ASSERT (is == 0); + /* U+E0033 TAG DIGIT THREE */ + is = for_character ("\363\240\200\263", 4); + ASSERT (is == 0); + /* U+E0041 TAG LATIN CAPITAL LETTER A */ + is = for_character ("\363\240\201\201", 4); + ASSERT (is == 0); + } + return 0; + + case '4': + /* Locale encoding is GB18030. */ + { + /* U+00B2 SUPERSCRIPT TWO */ + is = for_character ("\201\060\205\065", 4); + ASSERT (is == 0); + /* U+00B3 SUPERSCRIPT THREE */ + is = for_character ("\201\060\205\066", 4); + ASSERT (is == 0); + /* U+00B9 SUPERSCRIPT ONE */ + is = for_character ("\201\060\206\061", 4); + ASSERT (is == 0); + /* U+0663 ARABIC-INDIC DIGIT THREE */ + is = for_character ("\201\061\211\071", 4); + ASSERT (is == 0); + /* U+2070 SUPERSCRIPT ZERO */ + is = for_character ("\201\066\255\062", 4); + ASSERT (is == 0); + /* U+2079 SUPERSCRIPT NINE */ + is = for_character ("\201\066\256\061", 4); + ASSERT (is == 0); + /* U+FF11 FULLWIDTH DIGIT ONE */ + is = for_character ("\243\261", 2); + ASSERT (is == 0); + /* U+FF21 FULLWIDTH LATIN CAPITAL LETTER A */ + is = for_character ("\243\301", 2); + ASSERT (is == 0); + /* U+FF41 FULLWIDTH LATIN SMALL LETTER A */ + is = for_character ("\243\341", 2); + ASSERT (is == 0); + /* U+1D7D1 MATHEMATICAL BOLD DIGIT THREE */ + is = for_character ("\224\063\353\071", 4); + ASSERT (is == 0); + /* U+1D7DB MATHEMATICAL DOUBLE-STRUCK DIGIT THREE */ + is = for_character ("\224\063\354\071", 4); + ASSERT (is == 0); + /* U+1D7E5 MATHEMATICAL SANS-SERIF DIGIT THREE */ + is = for_character ("\224\063\355\071", 4); + ASSERT (is == 0); + /* U+1D7EF MATHEMATICAL SANS-SERIF BOLD DIGIT THREE */ + is = for_character ("\224\063\356\071", 4); + ASSERT (is == 0); + /* U+1D7F9 MATHEMATICAL MONOSPACE DIGIT THREE */ + is = for_character ("\224\063\357\071", 4); + ASSERT (is == 0); + /* U+E0033 TAG DIGIT THREE */ + is = for_character ("\323\066\232\071", 4); + ASSERT (is == 0); + /* U+E0041 TAG LATIN CAPITAL LETTER A */ + is = for_character ("\323\066\234\063", 4); + ASSERT (is == 0); + } + return 0; + + } + + return 1; +} diff --git a/tests/test-iswxdigit.sh b/tests/test-iswxdigit.sh new file mode 100755 index 0000000..f545438 --- /dev/null +++ b/tests/test-iswxdigit.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +# Test in the POSIX locale. +LC_ALL=C ${CHECKER} ./test-iswxdigit${EXEEXT} 0 || exit 1 +LC_ALL=POSIX ${CHECKER} ./test-iswxdigit${EXEEXT} 0 || exit 1 + +# Test in an ISO-8859-1 or ISO-8859-15 locale. +: ${LOCALE_FR=fr_FR} +if test $LOCALE_FR != none; then + LC_ALL=$LOCALE_FR \ + ${CHECKER} ./test-iswxdigit${EXEEXT} 1 \ + || exit 1 +fi + +# Test whether a specific EUC-JP locale is installed. +: ${LOCALE_JA=ja_JP} +if test $LOCALE_JA != none; then + LC_ALL=$LOCALE_JA \ + ${CHECKER} ./test-iswxdigit${EXEEXT} 2 \ + || exit 1 +fi + +# Test whether a specific UTF-8 locale is installed. +: ${LOCALE_FR_UTF8=fr_FR.UTF-8} +if test $LOCALE_FR_UTF8 != none; then + LC_ALL=$LOCALE_FR_UTF8 \ + ${CHECKER} ./test-iswxdigit${EXEEXT} 3 \ + || exit 1 +fi + +# Test whether a specific GB18030 locale is installed. +: ${LOCALE_ZH_CN=zh_CN.GB18030} +if test $LOCALE_ZH_CN != none; then + LC_ALL=$LOCALE_ZH_CN \ + ${CHECKER} ./test-iswxdigit${EXEEXT} 4 \ + || exit 1 +fi + +exit 0 -- 2.7.4
>From e79cf41f3c8607a78219955b5c04b398e7ff0ca9 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sat, 25 Jan 2020 21:19:27 +0100 Subject: [PATCH 3/3] mbchar, wctype: Use the corrected iswxdigit function. * modules/mbchar (Depends-on): Add iswxdigit. * modules/wctype (Depends-on): Likewise. --- ChangeLog | 4 ++++ modules/mbchar | 1 + modules/wctype | 1 + 3 files changed, 6 insertions(+) diff --git a/ChangeLog b/ChangeLog index f5a0863..28b3980 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2020-01-25 Bruno Haible <br...@clisp.org> + mbchar, wctype: Use the corrected iswxdigit function. + * modules/mbchar (Depends-on): Add iswxdigit. + * modules/wctype (Depends-on): Likewise. + iswxdigit: Add tests. * tests/test-iswxdigit.c: New file. * tests/test-iswxdigit.sh: New file. diff --git a/modules/mbchar b/modules/mbchar index b11e365..1a79abc 100644 --- a/modules/mbchar +++ b/modules/mbchar @@ -14,6 +14,7 @@ wchar wctype-h iswblank iswdigit +iswxdigit wcwidth memcmp diff --git a/modules/wctype b/modules/wctype index 2447c26..e653f62 100644 --- a/modules/wctype +++ b/modules/wctype @@ -16,6 +16,7 @@ Depends-on: wctype-h iswblank [test $HAVE_WCTYPE = 0] iswdigit [test $HAVE_WCTYPE = 0] +iswxdigit [test $HAVE_WCTYPE = 0] configure.ac: gl_FUNC_WCTYPE -- 2.7.4