2 dnl Copyright (C) 2020-2021 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
43 /* Returns the value of iswdigit for the multibyte character s[0..n-1]. */
45 for_character (const char *s, size_t n)
51 memset (&state, '\0', sizeof (mbstate_t));
52 wc = (wchar_t) 0xBADFACE;
53 ret = mbrtowc (&wc, s, n, &state);
61 main (int argc, char *argv[])
66 if (setlocale (LC_ALL, "$LOCALE_FR") != NULL)
68 /* This fails on mingw, MSVC 14. */
69 /* U+00B2 SUPERSCRIPT TWO */
70 is = for_character ("\262", 1);
74 if (setlocale (LC_ALL, "$LOCALE_JA") != NULL)
76 /* This fails on NetBSD 8.0. */
77 /* U+FF11 FULLWIDTH DIGIT ONE */
78 is = for_character ("\243\261", 2);
82 if (setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
84 /* This fails on FreeBSD 12, NetBSD 8.0, MSVC 14. */
85 /* U+0663 ARABIC-INDIC DIGIT THREE */
86 is = for_character ("\331\243", 2);
89 /* This fails on FreeBSD 12, NetBSD 8.0, MSVC 14. */
90 /* U+FF11 FULLWIDTH DIGIT ONE */
91 is = for_character ("\357\274\221", 3);
95 if (setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
97 /* This fails on NetBSD 8.0, Solaris 10, Solaris 11.4. */
98 /* U+FF11 FULLWIDTH DIGIT ONE */
99 is = for_character ("\243\261", 2);
105 [gl_cv_func_iswdigit_works=yes],
106 [gl_cv_func_iswdigit_works=no],
110 case "$gl_cv_func_iswdigit_works" in
112 *) REPLACE_ISWDIGIT=1 ;;