summaryrefslogtreecommitdiffstats
path: root/gl/m4/iswxdigit.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/iswxdigit.m4')
-rw-r--r--gl/m4/iswxdigit.m4112
1 files changed, 112 insertions, 0 deletions
diff --git a/gl/m4/iswxdigit.m4 b/gl/m4/iswxdigit.m4
new file mode 100644
index 00000000..95226fc4
--- /dev/null
+++ b/gl/m4/iswxdigit.m4
@@ -0,0 +1,112 @@
1# iswxdigit.m4
2# serial 9
3dnl Copyright (C) 2020-2025 Free Software Foundation, Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7dnl This file is offered as-is, without any warranty.
8
9AC_DEFUN([gl_FUNC_ISWXDIGIT],
10[
11 AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
12 AC_REQUIRE([gl_WCTYPE_H])
13 AC_REQUIRE([gt_LOCALE_JA])
14 AC_REQUIRE([gt_LOCALE_EN_UTF8])
15 AC_REQUIRE([gt_LOCALE_ZH_CN])
16 AC_REQUIRE([AC_CANONICAL_HOST])
17
18 if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
19 dnl <wctype.h> redefines iswxdigit already.
20 REPLACE_ISWXDIGIT="$REPLACE_ISWCNTRL"
21 else
22 AC_CACHE_CHECK([whether iswxdigit is ISO C compliant],
23 [gl_cv_func_iswxdigit_works],
24 [
25 dnl Initial guess, used when cross-compiling or when no suitable locale
26 dnl is present.
27changequote(,)dnl
28 case "$host_os" in
29 # Guess no on FreeBSD, NetBSD, OpenBSD, Solaris, native Windows, Haiku, Android.
30 freebsd* | dragonfly* | netbsd* | openbsd* | solaris* | mingw* | windows* | haiku* | *-android*)
31 gl_cv_func_iswxdigit_works="guessing no" ;;
32 # Guess yes otherwise.
33 *) gl_cv_func_iswxdigit_works="guessing yes" ;;
34 esac
35changequote([,])dnl
36 if test $LOCALE_JA != none || test "$LOCALE_EN_UTF8" != none || test $LOCALE_ZH_CN != none; then
37 AC_RUN_IFELSE(
38 [AC_LANG_SOURCE([[
39#include <locale.h>
40#include <stdlib.h>
41#include <string.h>
42#include <wchar.h>
43#include <wctype.h>
44
45/* Returns the value of iswxdigit for the multibyte character s[0..n-1]. */
46static int
47for_character (const char *s, size_t n)
48{
49 mbstate_t state;
50 wchar_t wc;
51 size_t ret;
52
53 memset (&state, '\0', sizeof (mbstate_t));
54 wc = (wchar_t) 0xBADFACE;
55 ret = mbrtowc (&wc, s, n, &state);
56 if (ret != n)
57 abort ();
58
59 return iswxdigit (wc);
60}
61
62int
63main (int argc, char *argv[])
64{
65 int is;
66 int result = 0;
67
68 if (strcmp ("$LOCALE_JA", "none") != 0
69 && setlocale (LC_ALL, "$LOCALE_JA") != NULL)
70 {
71 /* This fails on NetBSD 10.0. */
72 /* U+FF21 FULLWIDTH LATIN CAPITAL LETTER A */
73 is = for_character ("\243\301", 2);
74 if (!(is == 0))
75 result |= 1;
76 }
77 if (strcmp ("$LOCALE_EN_UTF8", "none") != 0
78 && setlocale (LC_ALL, "$LOCALE_EN_UTF8") != NULL)
79 {
80 /* This fails on FreeBSD 13.0, Haiku, Android. */
81 /* U+0663 ARABIC-INDIC DIGIT THREE */
82 is = for_character ("\331\243", 2);
83 if (!(is == 0))
84 result |= 2;
85 /* This fails on NetBSD 10.0, OpenBSD 7.5, MSVC 14, Haiku, Android. */
86 /* U+FF21 FULLWIDTH LATIN CAPITAL LETTER A */
87 is = for_character ("\357\274\241", 3);
88 if (!(is == 0))
89 result |= 4;
90 }
91 if (strcmp ("$LOCALE_ZH_CN", "none") != 0
92 && setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
93 {
94 /* This fails on Solaris 10, Solaris 11.4. */
95 /* U+FF11 FULLWIDTH DIGIT ONE */
96 is = for_character ("\243\261", 2);
97 if (!(is == 0))
98 result |= 8;
99 }
100 return result;
101}]])],
102 [gl_cv_func_iswxdigit_works=yes],
103 [gl_cv_func_iswxdigit_works=no],
104 [:])
105 fi
106 ])
107 case "$gl_cv_func_iswxdigit_works" in
108 *yes) ;;
109 *) REPLACE_ISWXDIGIT=1 ;;
110 esac
111 fi
112])