2 dnl Copyright (C) 2020 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_ISWDIGIT],
9 AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
10 AC_REQUIRE([gl_WCTYPE_H])
11 AC_REQUIRE([gt_LOCALE_FR])
12 AC_REQUIRE([gt_LOCALE_JA])
13 AC_REQUIRE([gt_LOCALE_FR_UTF8])
14 AC_REQUIRE([gt_LOCALE_ZH_CN])
16 if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
17 dnl <wctype.h> redefines iswdigit already.
18 REPLACE_ISWDIGIT="$REPLACE_ISWCNTRL"
20 AC_CACHE_CHECK([whether iswdigit is ISO C compliant],
21 [gl_cv_func_iswdigit_works],
23 dnl Initial guess, used when cross-compiling or when no suitable locale
27 # Guess no on FreeBSD, NetBSD, Solaris, native Windows.
28 freebsd* | dragonfly* | netbsd* | solaris* | mingw*)
29 gl_cv_func_iswdigit_works="guessing no" ;;
30 # Guess yes otherwise.
31 *) gl_cv_func_iswdigit_works="guessing yes" ;;
34 if test $LOCALE_FR != none || test $LOCALE_JA != none || test $LOCALE_FR_UTF8 != none || test $LOCALE_ZH_CN != none; then
40 /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
42 BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
43 included before <wchar.h>. */
50 /* Returns the value of iswdigit for the multibyte character s[0..n-1]. */
52 for_character (const char *s, size_t n)
58 memset (&state, '\0', sizeof (mbstate_t));
59 wc = (wchar_t) 0xBADFACE;
60 ret = mbrtowc (&wc, s, n, &state);
68 main (int argc, char *argv[])
73 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
75 /* This fails on mingw, MSVC 14. */
76 /* U+00B2 SUPERSCRIPT TWO */
77 is = for_character ("\262", 1);
81 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
83 /* This fails on NetBSD 8.0. */
84 /* U+FF11 FULLWIDTH DIGIT ONE */
85 is = for_character ("\243\261", 2);
89 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
91 /* This fails on FreeBSD 12, NetBSD 8.0, MSVC 14. */
92 /* U+0663 ARABIC-INDIC DIGIT THREE */
93 is = for_character ("\331\243", 2);
96 /* This fails on FreeBSD 12, NetBSD 8.0, MSVC 14. */
97 /* U+FF11 FULLWIDTH DIGIT ONE */
98 is = for_character ("\357\274\221", 3);
102 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
104 /* This fails on NetBSD 8.0, Solaris 10, Solaris 11.4. */
105 /* U+FF11 FULLWIDTH DIGIT ONE */
106 is = for_character ("\243\261", 2);
112 [gl_cv_func_iswdigit_works=yes],
113 [gl_cv_func_iswdigit_works=no],
117 case "$gl_cv_func_iswdigit_works" in
119 *) REPLACE_ISWDIGIT=1 ;;