c32isxdigit: Add tests.
[gnulib.git] / lib / uchar.in.h
blob9c76cc98786a82e7387ffceaf93ba47dd48b5909
1 /* <uchar.h> substitute - 16-bit and 32-bit wide character types.
2 Copyright (C) 2019-2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2019. */
20 * ISO C 11 <uchar.h> for platforms that lack it.
23 #ifndef _@GUARD_PREFIX@_UCHAR_H
25 #if __GNUC__ >= 3
26 @PRAGMA_SYSTEM_HEADER@
27 #endif
28 @PRAGMA_COLUMNS@
30 #if @HAVE_UCHAR_H@
31 # @INCLUDE_NEXT@ @NEXT_UCHAR_H@
32 #endif
34 /* Get uint_least16_t, uint_least32_t. */
35 #include <stdint.h>
37 /* Get mbstate_t, size_t. */
38 #include <wchar.h>
40 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
43 #if !@HAVE_UCHAR_H@
45 /* A 16-bit variant of wchar_t.
46 Note: This type does *NOT* denote UTF-16 units. (Only on platforms
47 on which __STDC_UTF_16__ is defined.) */
48 typedef uint_least16_t char16_t;
50 /* A 32-bit variant of wchar_t.
51 Note: This type does *NOT* denote UTF-32 code points. (Only on platforms
52 on which __STDC_UTF_32__ is defined.) */
53 typedef uint_least32_t char32_t;
55 #endif
57 /* Define if a 'char32_t' can hold more characters than a 'wchar_t'. */
58 #if @SMALL_WCHAR_T@ /* 32-bit AIX, Cygwin, native Windows */
59 # define _GL_LARGE_CHAR32_T 1
60 #endif
63 /* Convert a single-byte character to a 32-bit wide character. */
64 #if @GNULIB_BTOC32@
65 _GL_FUNCDECL_SYS (btoc32, wint_t, (int c) _GL_ATTRIBUTE_PURE);
66 _GL_CXXALIAS_SYS (btoc32, wint_t, (int c));
67 _GL_CXXALIASWARN (btoc32);
68 #endif
71 /* Test a specific property of a 32-bit wide character. */
72 #if @GNULIB_C32ISALNUM@
73 _GL_FUNCDECL_SYS (c32isalnum, int, (wint_t wc));
74 _GL_CXXALIAS_SYS (c32isalnum, int, (wint_t wc));
75 _GL_CXXALIASWARN (c32isalnum);
76 #endif
77 #if @GNULIB_C32ISALPHA@
78 _GL_FUNCDECL_SYS (c32isalpha, int, (wint_t wc));
79 _GL_CXXALIAS_SYS (c32isalpha, int, (wint_t wc));
80 _GL_CXXALIASWARN (c32isalpha);
81 #endif
82 #if @GNULIB_C32ISBLANK@
83 _GL_FUNCDECL_SYS (c32isblank, int, (wint_t wc));
84 _GL_CXXALIAS_SYS (c32isblank, int, (wint_t wc));
85 _GL_CXXALIASWARN (c32isblank);
86 #endif
87 #if @GNULIB_C32ISCNTRL@
88 _GL_FUNCDECL_SYS (c32iscntrl, int, (wint_t wc));
89 _GL_CXXALIAS_SYS (c32iscntrl, int, (wint_t wc));
90 _GL_CXXALIASWARN (c32iscntrl);
91 #endif
92 #if @GNULIB_C32ISDIGIT@
93 _GL_FUNCDECL_SYS (c32isdigit, int, (wint_t wc));
94 _GL_CXXALIAS_SYS (c32isdigit, int, (wint_t wc));
95 _GL_CXXALIASWARN (c32isdigit);
96 #endif
97 #if @GNULIB_C32ISGRAPH@
98 _GL_FUNCDECL_SYS (c32isgraph, int, (wint_t wc));
99 _GL_CXXALIAS_SYS (c32isgraph, int, (wint_t wc));
100 _GL_CXXALIASWARN (c32isgraph);
101 #endif
102 #if @GNULIB_C32ISLOWER@
103 _GL_FUNCDECL_SYS (c32islower, int, (wint_t wc));
104 _GL_CXXALIAS_SYS (c32islower, int, (wint_t wc));
105 _GL_CXXALIASWARN (c32islower);
106 #endif
107 #if @GNULIB_C32ISPRINT@
108 _GL_FUNCDECL_SYS (c32isprint, int, (wint_t wc));
109 _GL_CXXALIAS_SYS (c32isprint, int, (wint_t wc));
110 _GL_CXXALIASWARN (c32isprint);
111 #endif
112 #if @GNULIB_C32ISPUNCT@
113 _GL_FUNCDECL_SYS (c32ispunct, int, (wint_t wc));
114 _GL_CXXALIAS_SYS (c32ispunct, int, (wint_t wc));
115 _GL_CXXALIASWARN (c32ispunct);
116 #endif
117 #if @GNULIB_C32ISSPACE@
118 _GL_FUNCDECL_SYS (c32isspace, int, (wint_t wc));
119 _GL_CXXALIAS_SYS (c32isspace, int, (wint_t wc));
120 _GL_CXXALIASWARN (c32isspace);
121 #endif
122 #if @GNULIB_C32ISUPPER@
123 _GL_FUNCDECL_SYS (c32isupper, int, (wint_t wc));
124 _GL_CXXALIAS_SYS (c32isupper, int, (wint_t wc));
125 _GL_CXXALIASWARN (c32isupper);
126 #endif
127 #if @GNULIB_C32ISXDIGIT@
128 _GL_FUNCDECL_SYS (c32isxdigit, int, (wint_t wc));
129 _GL_CXXALIAS_SYS (c32isxdigit, int, (wint_t wc));
130 _GL_CXXALIASWARN (c32isxdigit);
131 #endif
134 /* Converts a 32-bit wide character to a multibyte character. */
135 #if @GNULIB_C32RTOMB@
136 # if @REPLACE_C32RTOMB@
137 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
138 # undef c32rtomb
139 # define c32rtomb rpl_c32rtomb
140 # endif
141 _GL_FUNCDECL_RPL (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
142 _GL_CXXALIAS_RPL (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
143 # else
144 # if !@HAVE_C32RTOMB@
145 _GL_FUNCDECL_SYS (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
146 # endif
147 _GL_CXXALIAS_SYS (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
148 # endif
149 _GL_CXXALIASWARN (c32rtomb);
150 #elif defined GNULIB_POSIXCHECK
151 # undef c32rtomb
152 # if HAVE_RAW_DECL_C32RTOMB
153 _GL_WARN_ON_USE (mbrtoc32, "c32rtomb is not portable - "
154 "use gnulib module c32rtomb for portability");
155 # endif
156 #endif
159 /* Convert a 32-bit wide string to a string. */
160 #if @GNULIB_C32SNRTOMBS@
161 _GL_FUNCDECL_SYS (c32snrtombs, size_t,
162 (char *dest, const char32_t **srcp, size_t srclen, size_t len,
163 mbstate_t *ps)
164 _GL_ARG_NONNULL ((2)));
165 _GL_CXXALIAS_SYS (c32snrtombs, size_t,
166 (char *dest, const char32_t **srcp, size_t srclen, size_t len,
167 mbstate_t *ps));
168 _GL_CXXALIASWARN (c32snrtombs);
169 #endif
172 /* Convert a 32-bit wide string to a string. */
173 #if @GNULIB_C32SRTOMBS@
174 _GL_FUNCDECL_SYS (c32srtombs, size_t,
175 (char *dest, const char32_t **srcp, size_t len, mbstate_t *ps)
176 _GL_ARG_NONNULL ((2)));
177 _GL_CXXALIAS_SYS (c32srtombs, size_t,
178 (char *dest, const char32_t **srcp, size_t len,
179 mbstate_t *ps));
180 _GL_CXXALIASWARN (c32srtombs);
181 #endif
184 /* Convert a 32-bit wide string to a string. */
185 #if @GNULIB_C32STOMBS@
186 _GL_FUNCDECL_SYS (c32stombs, size_t,
187 (char *dest, const char32_t *src, size_t len)
188 _GL_ARG_NONNULL ((2)));
189 _GL_CXXALIAS_SYS (c32stombs, size_t,
190 (char *dest, const char32_t *src, size_t len));
191 _GL_CXXALIASWARN (c32stombs);
192 #endif
195 /* Converts a 32-bit wide character to unibyte character.
196 Returns the single-byte representation of WC if it exists,
197 or EOF otherwise. */
198 #if @GNULIB_C32TOB@
199 _GL_FUNCDECL_SYS (c32tob, int, (wint_t wc));
200 _GL_CXXALIAS_SYS (c32tob, int, (wint_t wc));
201 _GL_CXXALIASWARN (c32tob);
202 #endif
205 /* Converts a multibyte character to a 32-bit wide character. */
206 #if @GNULIB_MBRTOC32@
207 # if @REPLACE_MBRTOC32@
208 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
209 # undef mbrtoc32
210 # define mbrtoc32 rpl_mbrtoc32
211 # endif
212 _GL_FUNCDECL_RPL (mbrtoc32, size_t,
213 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
214 _GL_CXXALIAS_RPL (mbrtoc32, size_t,
215 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
216 # else
217 # if !@HAVE_MBRTOC32@
218 _GL_FUNCDECL_SYS (mbrtoc32, size_t,
219 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
220 # endif
221 _GL_CXXALIAS_SYS (mbrtoc32, size_t,
222 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
223 # endif
224 _GL_CXXALIASWARN (mbrtoc32);
225 #elif defined GNULIB_POSIXCHECK
226 # undef mbrtoc32
227 # if HAVE_RAW_DECL_MBRTOC32
228 _GL_WARN_ON_USE (mbrtoc32, "mbrtoc32 is not portable - "
229 "use gnulib module mbrtoc32 for portability");
230 # endif
231 #endif
234 /* Convert a string to a 32-bit wide string. */
235 #if @GNULIB_MBSNRTOC32S@
236 _GL_FUNCDECL_SYS (mbsnrtoc32s, size_t,
237 (char32_t *dest, const char **srcp, size_t srclen, size_t len,
238 mbstate_t *ps)
239 _GL_ARG_NONNULL ((2)));
240 _GL_CXXALIAS_SYS (mbsnrtoc32s, size_t,
241 (char32_t *dest, const char **srcp, size_t srclen, size_t len,
242 mbstate_t *ps));
243 _GL_CXXALIASWARN (mbsnrtoc32s);
244 #endif
247 /* Convert a string to a 32-bit wide string. */
248 #if @GNULIB_MBSRTOC32S@
249 _GL_FUNCDECL_SYS (mbsrtoc32s, size_t,
250 (char32_t *dest, const char **srcp, size_t len, mbstate_t *ps)
251 _GL_ARG_NONNULL ((2)));
252 _GL_CXXALIAS_SYS (mbsrtoc32s, size_t,
253 (char32_t *dest, const char **srcp, size_t len,
254 mbstate_t *ps));
255 _GL_CXXALIASWARN (mbsrtoc32s);
256 #endif
259 /* Convert a string to a 32-bit wide string. */
260 #if @GNULIB_MBSTOC32S@
261 _GL_FUNCDECL_SYS (mbstoc32s, size_t,
262 (char32_t *dest, const char *src, size_t len)
263 _GL_ARG_NONNULL ((2)));
264 _GL_CXXALIAS_SYS (mbstoc32s, size_t,
265 (char32_t *dest, const char *src, size_t len));
266 _GL_CXXALIASWARN (mbstoc32s);
267 #endif
270 #endif /* _@GUARD_PREFIX@_UCHAR_H */