summaryrefslogtreecommitdiffstats
path: root/gl/m4/iswdigit.m4
diff options
context:
space:
mode:
Diffstat (limited to 'gl/m4/iswdigit.m4')
-rw-r--r--gl/m4/iswdigit.m4121
1 files changed, 121 insertions, 0 deletions
diff --git a/gl/m4/iswdigit.m4 b/gl/m4/iswdigit.m4
new file mode 100644
index 0000000..999acd2
--- /dev/null
+++ b/gl/m4/iswdigit.m4
@@ -0,0 +1,121 @@
1# iswdigit.m4
2# serial 7
3dnl Copyright (C) 2020-2024 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.
7
8AC_DEFUN([gl_FUNC_ISWDIGIT],
9[
10 AC_REQUIRE([gl_WCTYPE_H_DEFAULTS])
11 AC_REQUIRE([gl_WCTYPE_H])
12 AC_REQUIRE([gt_LOCALE_FR])
13 AC_REQUIRE([gt_LOCALE_JA])
14 AC_REQUIRE([gt_LOCALE_FR_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 iswdigit already.
20 REPLACE_ISWDIGIT="$REPLACE_ISWCNTRL"
21 else
22 AC_CACHE_CHECK([whether iswdigit is ISO C compliant],
23 [gl_cv_func_iswdigit_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, Solaris, native Windows.
30 freebsd* | dragonfly* | netbsd* | solaris* | mingw* | windows*)
31 gl_cv_func_iswdigit_works="guessing no" ;;
32 # Guess yes otherwise.
33 *) gl_cv_func_iswdigit_works="guessing yes" ;;
34 esac
35changequote([,])dnl
36 if test $LOCALE_FR != none || test $LOCALE_JA != none || test $LOCALE_FR_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 iswdigit 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 iswdigit (wc);
60}
61
62int
63main (int argc, char *argv[])
64{
65 int is;
66 int result = 0;
67
68 if (strcmp ("$LOCALE_FR", "none") != 0
69 && setlocale (LC_ALL, "$LOCALE_FR") != NULL)
70 {
71 /* This fails on mingw, MSVC 14. */
72 /* U+00B2 SUPERSCRIPT TWO */
73 is = for_character ("\262", 1);
74 if (!(is == 0))
75 result |= 1;
76 }
77 if (strcmp ("$LOCALE_JA", "none") != 0
78 && setlocale (LC_ALL, "$LOCALE_JA") != NULL)
79 {
80 /* This fails on NetBSD 10.0. */
81 /* U+FF11 FULLWIDTH DIGIT ONE */
82 is = for_character ("\243\261", 2);
83 if (!(is == 0))
84 result |= 2;
85 }
86 if (strcmp ("$LOCALE_FR_UTF8", "none") != 0
87 && setlocale (LC_ALL, "$LOCALE_FR_UTF8") != NULL)
88 {
89 /* This fails on FreeBSD 13.0, NetBSD 10.0, MSVC 14. */
90 /* U+0663 ARABIC-INDIC DIGIT THREE */
91 is = for_character ("\331\243", 2);
92 if (!(is == 0))
93 result |= 4;
94 /* This fails on FreeBSD 13.0, NetBSD 10.0, MSVC 14. */
95 /* U+FF11 FULLWIDTH DIGIT ONE */
96 is = for_character ("\357\274\221", 3);
97 if (!(is == 0))
98 result |= 8;
99 }
100 if (strcmp ("$LOCALE_ZH_CN", "none") != 0
101 && setlocale (LC_ALL, "$LOCALE_ZH_CN") != NULL)
102 {
103 /* This fails on NetBSD 10.0, Solaris 10, Solaris 11.4. */
104 /* U+FF11 FULLWIDTH DIGIT ONE */
105 is = for_character ("\243\261", 2);
106 if (!(is == 0))
107 result |= 16;
108 }
109 return result;
110}]])],
111 [gl_cv_func_iswdigit_works=yes],
112 [gl_cv_func_iswdigit_works=no],
113 [:])
114 fi
115 ])
116 case "$gl_cv_func_iswdigit_works" in
117 *yes) ;;
118 *) REPLACE_ISWDIGIT=1 ;;
119 esac
120 fi
121])