Debian Codegraph @

lib/uchar.in.h

raw
1 /* <uchar.h> substitute - 16-bit and 32-bit wide character types.
2 Copyright (C) 2019-2026 Free Software Foundation, Inc.
3
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
8
9 This file 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 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17 /* Written by Bruno Haible <[email protected]>, 2019. */
18
19 /*
20 * ISO C 23 <uchar.h> for platforms that lack it.
21 */
22
23 #ifndef _@GUARD_PREFIX@_UCHAR_H
24
25 #if __GNUC__ >= 3
26 @PRAGMA_SYSTEM_HEADER@
27 #endif
28 @PRAGMA_COLUMNS@
29
30 /* The include_next requires a split double-inclusion guard. */
31 #if (defined __cplusplus ? @CXX_HAVE_UCHAR_H@ : @HAVE_UCHAR_H@)
32 # if defined __HAIKU__
33 /* Work around <https://dev.haiku-os.org/ticket/17040>. */
34 # include <stdint.h>
35 # endif
36 /* On AIX 7.2 with xlclang++, /usr/include/uchar.h produces compilation errors
37 because it contains typedef definitions of char16_t and char32_t, however
38 char16_t and char32_t are keywords in this situation. To work around it,
39 define char16_t and char32_t as macros. */
40 # if defined __cplusplus && defined _AIX && defined __ibmxl__ && defined __clang__
41 # define char16_t gl_char16_t
42 # define char32_t gl_char32_t
43 # endif
44 # @INCLUDE_NEXT@ @NEXT_UCHAR_H@
45 #endif
46
47 #ifndef _@GUARD_PREFIX@_UCHAR_H
48 #define _@GUARD_PREFIX@_UCHAR_H
49
50 /* This file uses _GL_INLINE_HEADER_BEGIN, _GL_INLINE, _GL_BEGIN_C_LINKAGE,
51 _GL_ATTRIBUTE_PURE, GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
52 #if !_GL_CONFIG_H_INCLUDED
53 #error "Please include config.h first."
54 #endif
55
56 /* Get uint_least16_t, uint_least32_t. */
57 #include <stdint.h>
58
59 /* Get mbstate_t, size_t. */
60 #include <wchar.h>
61
62 /* For the inline functions. */
63 #include <string.h>
64 #include <wctype.h>
65
66 /* The __attribute__ feature is available in gcc versions 2.5 and later.
67 The attribute __pure__ was added in gcc 2.96. */
68 #ifndef _GL_ATTRIBUTE_PURE
69 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) || defined __clang__
70 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__))
71 # else
72 # define _GL_ATTRIBUTE_PURE /* empty */
73 # endif
74 #endif
75
76 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
77
78 /* The definition of _GL_ARG_NONNULL is copied here. */
79
80 /* The definition of _GL_WARN_ON_USE is copied here. */
81
82
83 _GL_INLINE_HEADER_BEGIN
84
85
86 #if !(defined __cplusplus ? @CXX_HAVE_UCHAR_H@ || @CXX_HAS_CHAR8_TYPE@ : @HAVE_UCHAR_H@)
87
88 /* An 8-bit variant of wchar_t.
89 Note: This type is only mandated by ISO C 23 or newer, and it does
90 denote UTF-8 units. */
91 typedef unsigned char char8_t;
92
93 #elif @GNULIBHEADERS_OVERRIDE_CHAR8_T@
94
95 typedef unsigned char gl_char8_t;
96 # define char8_t gl_char8_t
97
98 #endif
99
100 #if !(defined __cplusplus ? @CXX_HAVE_UCHAR_H@ || @CXX_HAS_UCHAR_TYPES@ : @HAVE_UCHAR_H@)
101
102 /* A 16-bit variant of wchar_t.
103 Note: This type is only mandated by ISO C 11 or newer. In ISO C 23
104 and newer, it denotes UTF-16 units; in older versions of ISO C it did
105 so only on platforms on which __STDC_UTF_16__ was defined. */
106 typedef uint_least16_t char16_t;
107
108 #elif @GNULIBHEADERS_OVERRIDE_CHAR16_T@
109
110 typedef uint_least16_t gl_char16_t;
111 # define char16_t gl_char16_t
112
113 #endif
114
115 #if !(defined __cplusplus ? @CXX_HAVE_UCHAR_H@ || @CXX_HAS_UCHAR_TYPES@ : @HAVE_UCHAR_H@)
116
117 /* A 32-bit variant of wchar_t.
118 Note: This type is only mandated by ISO C 11 or newer. In ISO C 23
119 and newer, it denotes UTF-32 code points; in older versions of ISO C
120 it did so only on platforms on which __STDC_UTF_32__ was defined.
121 In gnulib, we guarantee that it denotes UTF-32 code points if and
122 only if the module 'uchar-h-c23' is in use. */
123 typedef uint_least32_t char32_t;
124
125 #elif @GNULIBHEADERS_OVERRIDE_CHAR32_T@
126
127 typedef uint_least32_t gl_char32_t;
128 # define char32_t gl_char32_t
129
130 #endif
131
132 /* Define if a 'char32_t' can hold more characters than a 'wchar_t'. */
133 #if @SMALL_WCHAR_T@ /* 32-bit AIX, Cygwin, native Windows */
134 # define _GL_SMALL_WCHAR_T 1
135 #endif
136
137 /* Define if 'wchar_t', like 'char32_t',
138 - is a 32-bit type, and
139 - represents Unicode code points.
140 For this test, we can use __STDC_ISO_10646__ (defined by glibc, musl libc,
141 Cygwin) but need to consider _GL_SMALL_WCHAR_T, so as to exclude Cygwin.
142 We cannot use __STDC_UTF_16__ or __STDC_UTF_32__
143 - because these macros provide info about char16_t and char32_t (not
144 wchar_t!), and
145 - because GCC >= 4.9 defines these macros on all platforms, even on
146 FreeBSD and Solaris.
147 We should better not use __STD_UTF_16__, __STD_UTF_32__ either, because
148 these macros are misspellings, only defined by Android's <uchar.h>. */
149 #if defined __STDC_ISO_10646__ && !_GL_SMALL_WCHAR_T
150 /* glibc, musl libc */
151 # define _GL_WCHAR_T_IS_UCS4 1
152 #endif
153 #if _GL_WCHAR_T_IS_UCS4
154 static_assert (sizeof (char32_t) == sizeof (wchar_t));
155 #endif
156
157
158 /* Convert a single-byte character to a 32-bit wide character. */
159 #if @GNULIB_BTOC32@
160 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_BTOC32
161 _GL_BEGIN_C_LINKAGE
162 _GL_INLINE _GL_ATTRIBUTE_PURE wint_t
163 btoc32 (int c)
164 {
165 return
166 # if @GNULIB_BTOWC@ && defined __cplusplus && defined GNULIB_NAMESPACE
167 GNULIB_NAMESPACE::
168 # endif
169 btowc (c);
170 }
171 _GL_END_C_LINKAGE
172 # else
173 _GL_FUNCDECL_SYS (btoc32, wint_t, (int c), _GL_ATTRIBUTE_PURE);
174 # endif
175 _GL_CXXALIAS_SYS (btoc32, wint_t, (int c));
176 _GL_CXXALIASWARN (btoc32);
177 #endif
178
179
180 /* Test a specific property of a 32-bit wide character. */
181 #if @GNULIB_C32ISALNUM@
182 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISALNUM
183 _GL_BEGIN_C_LINKAGE
184 _GL_INLINE int
185 c32isalnum (wint_t wc)
186 {
187 return
188 # if defined __cplusplus && defined GNULIB_NAMESPACE
189 GNULIB_NAMESPACE::
190 # endif
191 iswalnum (wc);
192 }
193 _GL_END_C_LINKAGE
194 # else
195 _GL_FUNCDECL_SYS (c32isalnum, int, (wint_t wc), );
196 # endif
197 _GL_CXXALIAS_SYS (c32isalnum, int, (wint_t wc));
198 _GL_CXXALIASWARN (c32isalnum);
199 #endif
200 #if @GNULIB_C32ISALPHA@
201 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISALPHA
202 _GL_BEGIN_C_LINKAGE
203 _GL_INLINE int
204 c32isalpha (wint_t wc)
205 {
206 return
207 # if defined __cplusplus && defined GNULIB_NAMESPACE
208 GNULIB_NAMESPACE::
209 # endif
210 iswalpha (wc);
211 }
212 _GL_END_C_LINKAGE
213 # else
214 _GL_FUNCDECL_SYS (c32isalpha, int, (wint_t wc), );
215 # endif
216 _GL_CXXALIAS_SYS (c32isalpha, int, (wint_t wc));
217 _GL_CXXALIASWARN (c32isalpha);
218 #endif
219 #if @GNULIB_C32ISBLANK@
220 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISBLANK
221 _GL_BEGIN_C_LINKAGE
222 _GL_INLINE int
223 c32isblank (wint_t wc)
224 {
225 return
226 # if defined __cplusplus && defined GNULIB_NAMESPACE
227 GNULIB_NAMESPACE::
228 # endif
229 iswblank (wc);
230 }
231 _GL_END_C_LINKAGE
232 # else
233 _GL_FUNCDECL_SYS (c32isblank, int, (wint_t wc), );
234 # endif
235 _GL_CXXALIAS_SYS (c32isblank, int, (wint_t wc));
236 _GL_CXXALIASWARN (c32isblank);
237 #endif
238 #if @GNULIB_C32ISCNTRL@
239 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISCNTRL
240 _GL_BEGIN_C_LINKAGE
241 _GL_INLINE int
242 c32iscntrl (wint_t wc)
243 {
244 return
245 # if defined __cplusplus && defined GNULIB_NAMESPACE
246 GNULIB_NAMESPACE::
247 # endif
248 iswcntrl (wc);
249 }
250 _GL_END_C_LINKAGE
251 # else
252 _GL_FUNCDECL_SYS (c32iscntrl, int, (wint_t wc), );
253 # endif
254 _GL_CXXALIAS_SYS (c32iscntrl, int, (wint_t wc));
255 _GL_CXXALIASWARN (c32iscntrl);
256 #endif
257 #if @GNULIB_C32ISDIGIT@
258 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISDIGIT
259 _GL_BEGIN_C_LINKAGE
260 _GL_INLINE int
261 c32isdigit (wint_t wc)
262 {
263 return
264 # if @GNULIB_ISWDIGIT@ && defined __cplusplus && defined GNULIB_NAMESPACE
265 GNULIB_NAMESPACE::
266 # endif
267 iswdigit (wc);
268 }
269 _GL_END_C_LINKAGE
270 # else
271 _GL_FUNCDECL_SYS (c32isdigit, int, (wint_t wc), );
272 # endif
273 _GL_CXXALIAS_SYS (c32isdigit, int, (wint_t wc));
274 _GL_CXXALIASWARN (c32isdigit);
275 #endif
276 #if @GNULIB_C32ISGRAPH@
277 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISGRAPH
278 _GL_BEGIN_C_LINKAGE
279 _GL_INLINE int
280 c32isgraph (wint_t wc)
281 {
282 return
283 # if defined __cplusplus && defined GNULIB_NAMESPACE
284 GNULIB_NAMESPACE::
285 # endif
286 iswgraph (wc);
287 }
288 _GL_END_C_LINKAGE
289 # else
290 _GL_FUNCDECL_SYS (c32isgraph, int, (wint_t wc), );
291 # endif
292 _GL_CXXALIAS_SYS (c32isgraph, int, (wint_t wc));
293 _GL_CXXALIASWARN (c32isgraph);
294 #endif
295 #if @GNULIB_C32ISLOWER@
296 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISLOWER
297 _GL_BEGIN_C_LINKAGE
298 _GL_INLINE int
299 c32islower (wint_t wc)
300 {
301 return
302 # if defined __cplusplus && defined GNULIB_NAMESPACE
303 GNULIB_NAMESPACE::
304 # endif
305 iswlower (wc);
306 }
307 _GL_END_C_LINKAGE
308 # else
309 _GL_FUNCDECL_SYS (c32islower, int, (wint_t wc), );
310 # endif
311 _GL_CXXALIAS_SYS (c32islower, int, (wint_t wc));
312 _GL_CXXALIASWARN (c32islower);
313 #endif
314 #if @GNULIB_C32ISPRINT@
315 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISPRINT
316 _GL_BEGIN_C_LINKAGE
317 _GL_INLINE int
318 c32isprint (wint_t wc)
319 {
320 return
321 # if defined __cplusplus && defined GNULIB_NAMESPACE
322 GNULIB_NAMESPACE::
323 # endif
324 iswprint (wc);
325 }
326 _GL_END_C_LINKAGE
327 # else
328 _GL_FUNCDECL_SYS (c32isprint, int, (wint_t wc), );
329 # endif
330 _GL_CXXALIAS_SYS (c32isprint, int, (wint_t wc));
331 _GL_CXXALIASWARN (c32isprint);
332 #endif
333 #if @GNULIB_C32ISPUNCT@
334 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISPUNCT
335 _GL_BEGIN_C_LINKAGE
336 _GL_INLINE int
337 c32ispunct (wint_t wc)
338 {
339 return
340 # if defined __cplusplus && defined GNULIB_NAMESPACE
341 GNULIB_NAMESPACE::
342 # endif
343 iswpunct (wc);
344 }
345 _GL_END_C_LINKAGE
346 # else
347 _GL_FUNCDECL_SYS (c32ispunct, int, (wint_t wc), );
348 # endif
349 _GL_CXXALIAS_SYS (c32ispunct, int, (wint_t wc));
350 _GL_CXXALIASWARN (c32ispunct);
351 #endif
352 #if @GNULIB_C32ISSPACE@
353 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISSPACE
354 _GL_BEGIN_C_LINKAGE
355 _GL_INLINE int
356 c32isspace (wint_t wc)
357 {
358 return
359 # if defined __cplusplus && defined GNULIB_NAMESPACE
360 GNULIB_NAMESPACE::
361 # endif
362 iswspace (wc);
363 }
364 _GL_END_C_LINKAGE
365 # else
366 _GL_FUNCDECL_SYS (c32isspace, int, (wint_t wc), );
367 # endif
368 _GL_CXXALIAS_SYS (c32isspace, int, (wint_t wc));
369 _GL_CXXALIASWARN (c32isspace);
370 #endif
371 #if @GNULIB_C32ISUPPER@
372 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISUPPER
373 _GL_BEGIN_C_LINKAGE
374 _GL_INLINE int
375 c32isupper (wint_t wc)
376 {
377 return
378 # if defined __cplusplus && defined GNULIB_NAMESPACE
379 GNULIB_NAMESPACE::
380 # endif
381 iswupper (wc);
382 }
383 _GL_END_C_LINKAGE
384 # else
385 _GL_FUNCDECL_SYS (c32isupper, int, (wint_t wc), );
386 # endif
387 _GL_CXXALIAS_SYS (c32isupper, int, (wint_t wc));
388 _GL_CXXALIASWARN (c32isupper);
389 #endif
390 #if @GNULIB_C32ISXDIGIT@
391 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32ISXDIGIT
392 _GL_BEGIN_C_LINKAGE
393 _GL_INLINE int
394 c32isxdigit (wint_t wc)
395 {
396 return
397 # if @GNULIB_ISWXDIGIT@ && defined __cplusplus && defined GNULIB_NAMESPACE
398 GNULIB_NAMESPACE::
399 # endif
400 iswxdigit (wc);
401 }
402 _GL_END_C_LINKAGE
403 # else
404 _GL_FUNCDECL_SYS (c32isxdigit, int, (wint_t wc), );
405 # endif
406 _GL_CXXALIAS_SYS (c32isxdigit, int, (wint_t wc));
407 _GL_CXXALIASWARN (c32isxdigit);
408 #endif
409
410
411 /* Case mapping of a 32-bit wide character. */
412 #if @GNULIB_C32TOLOWER@
413 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32TOLOWER
414 _GL_BEGIN_C_LINKAGE
415 _GL_INLINE wint_t
416 c32tolower (wint_t wc)
417 {
418 return
419 # if defined __cplusplus && defined GNULIB_NAMESPACE
420 GNULIB_NAMESPACE::
421 # endif
422 towlower (wc);
423 }
424 _GL_END_C_LINKAGE
425 # else
426 _GL_FUNCDECL_SYS (c32tolower, wint_t, (wint_t wc), );
427 # endif
428 _GL_CXXALIAS_SYS (c32tolower, wint_t, (wint_t wc));
429 _GL_CXXALIASWARN (c32tolower);
430 #endif
431 #if @GNULIB_C32TOUPPER@
432 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32TOUPPER
433 _GL_BEGIN_C_LINKAGE
434 _GL_INLINE wint_t
435 c32toupper (wint_t wc)
436 {
437 return
438 # if defined __cplusplus && defined GNULIB_NAMESPACE
439 GNULIB_NAMESPACE::
440 # endif
441 towupper (wc);
442 }
443 _GL_END_C_LINKAGE
444 # else
445 _GL_FUNCDECL_SYS (c32toupper, wint_t, (wint_t wc), );
446 # endif
447 _GL_CXXALIAS_SYS (c32toupper, wint_t, (wint_t wc));
448 _GL_CXXALIASWARN (c32toupper);
449 #endif
450
451
452 /* Number of screen columns needed for a 32-bit wide character. */
453 #if @GNULIB_C32WIDTH@
454 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32WIDTH
455 _GL_BEGIN_C_LINKAGE
456 _GL_INLINE int
457 c32width (char32_t wc)
458 {
459 return
460 # if @GNULIB_WCWIDTH@ && defined __cplusplus && defined GNULIB_NAMESPACE
461 GNULIB_NAMESPACE::
462 # endif
463 wcwidth (wc);
464 }
465 _GL_END_C_LINKAGE
466 # else
467 _GL_FUNCDECL_SYS (c32width, int, (char32_t wc), );
468 # endif
469 _GL_CXXALIAS_SYS (c32width, int, (char32_t wc));
470 _GL_CXXALIASWARN (c32width);
471 #endif
472
473
474 /* Converts a 32-bit wide character to a multibyte character. */
475 #if @GNULIB_C32RTOMB@
476 # if @REPLACE_C32RTOMB@
477 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
478 # undef c32rtomb
479 # define c32rtomb rpl_c32rtomb
480 # endif
481 _GL_FUNCDECL_RPL (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps), );
482 _GL_CXXALIAS_RPL (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
483 # else
484 # if !@HAVE_C32RTOMB@
485 _GL_FUNCDECL_SYS (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps), );
486 # endif
487 _GL_CXXALIAS_SYS (c32rtomb, size_t, (char *s, char32_t wc, mbstate_t *ps));
488 # endif
489 # if __GLIBC__ + (__GLIBC_MINOR__ >= 16) > 2
490 _GL_CXXALIASWARN (c32rtomb);
491 # endif
492 #elif defined GNULIB_POSIXCHECK
493 # if HAVE_RAW_DECL_C32RTOMB
494 _GL_WARN_ON_USE (c32rtomb, "c32rtomb is not portable - "
495 "use gnulib module c32rtomb for portability");
496 # endif
497 #endif
498
499
500 /* Convert a 32-bit wide string to a string. */
501 #if @GNULIB_C32SNRTOMBS@
502 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32SNRTOMBS
503 _GL_BEGIN_C_LINKAGE
504 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
505 c32snrtombs (char *dest, const char32_t **srcp, size_t srclen, size_t len,
506 mbstate_t *ps)
507 {
508 return
509 # if @GNULIB_WCSNRTOMBS@ && defined __cplusplus && defined GNULIB_NAMESPACE
510 GNULIB_NAMESPACE::
511 # endif
512 wcsnrtombs (dest, (const wchar_t **) srcp, srclen, len, ps);
513 }
514 _GL_END_C_LINKAGE
515 # else
516 _GL_FUNCDECL_SYS (c32snrtombs, size_t,
517 (char *dest, const char32_t **srcp, size_t srclen, size_t len,
518 mbstate_t *ps),
519 _GL_ARG_NONNULL ((2)));
520 # endif
521 _GL_CXXALIAS_SYS (c32snrtombs, size_t,
522 (char *dest, const char32_t **srcp, size_t srclen, size_t len,
523 mbstate_t *ps));
524 _GL_CXXALIASWARN (c32snrtombs);
525 #endif
526
527
528 /* Convert a 32-bit wide string to a string. */
529 #if @GNULIB_C32SRTOMBS@
530 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32SRTOMBS
531 _GL_BEGIN_C_LINKAGE
532 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
533 c32srtombs (char *dest, const char32_t **srcp, size_t len, mbstate_t *ps)
534 {
535 return
536 # if @GNULIB_WCSRTOMBS@ && defined __cplusplus && defined GNULIB_NAMESPACE
537 GNULIB_NAMESPACE::
538 # endif
539 wcsrtombs (dest, (const wchar_t **) srcp, len, ps);
540 }
541 _GL_END_C_LINKAGE
542 # else
543 _GL_FUNCDECL_SYS (c32srtombs, size_t,
544 (char *dest, const char32_t **srcp, size_t len,
545 mbstate_t *ps),
546 _GL_ARG_NONNULL ((2)));
547 # endif
548 _GL_CXXALIAS_SYS (c32srtombs, size_t,
549 (char *dest, const char32_t **srcp, size_t len,
550 mbstate_t *ps));
551 _GL_CXXALIASWARN (c32srtombs);
552 #endif
553
554
555 /* Convert a 32-bit wide string to a string. */
556 #if @GNULIB_C32STOMBS@
557 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32STOMBS
558 _GL_BEGIN_C_LINKAGE
559 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
560 c32stombs (char *dest, const char32_t *src, size_t len)
561 {
562 mbstate_t state;
563
564 mbszero (&state);
565 return c32srtombs (dest, &src, len, &state);
566 }
567 _GL_END_C_LINKAGE
568 # else
569 _GL_FUNCDECL_SYS (c32stombs, size_t,
570 (char *dest, const char32_t *src, size_t len),
571 _GL_ARG_NONNULL ((2)));
572 # endif
573 _GL_CXXALIAS_SYS (c32stombs, size_t,
574 (char *dest, const char32_t *src, size_t len));
575 _GL_CXXALIASWARN (c32stombs);
576 #endif
577
578
579 /* Number of screen columns needed for a size-bounded 32-bit wide string. */
580 #if @GNULIB_C32SWIDTH@
581 # if (_GL_WCHAR_T_IS_UCS4 && !GNULIB_defined_mbstate_t) && !defined IN_C32SWIDTH
582 _GL_BEGIN_C_LINKAGE
583 _GL_INLINE _GL_ARG_NONNULL ((1)) int
584 c32swidth (const char32_t *s, size_t n)
585 {
586 return
587 # if @GNULIB_WCSWIDTH@ && defined __cplusplus && defined GNULIB_NAMESPACE
588 GNULIB_NAMESPACE::
589 # endif
590 wcswidth ((const wchar_t *) s, n);
591 }
592 _GL_END_C_LINKAGE
593 # else
594 _GL_FUNCDECL_SYS (c32swidth, int, (const char32_t *s, size_t n),
595 _GL_ARG_NONNULL ((1)));
596 # endif
597 _GL_CXXALIAS_SYS (c32swidth, int, (const char32_t *s, size_t n));
598 _GL_CXXALIASWARN (c32swidth);
599 #endif
600
601
602 /* Converts a 32-bit wide character to unibyte character.
603 Returns the single-byte representation of WC if it exists,
604 or EOF otherwise. */
605 #if @GNULIB_C32TOB@
606 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32TOB
607 _GL_BEGIN_C_LINKAGE
608 _GL_INLINE int
609 c32tob (wint_t wc)
610 {
611 return
612 # if @GNULIB_WCTOB@ && defined __cplusplus && defined GNULIB_NAMESPACE
613 GNULIB_NAMESPACE::
614 # endif
615 wctob (wc);
616 }
617 _GL_END_C_LINKAGE
618 # else
619 _GL_FUNCDECL_SYS (c32tob, int, (wint_t wc), );
620 # endif
621 _GL_CXXALIAS_SYS (c32tob, int, (wint_t wc));
622 _GL_CXXALIASWARN (c32tob);
623 #endif
624
625
626 /* Converts a multibyte character to a 32-bit wide character. */
627 #if @GNULIB_MBRTOC32@
628 # if @REPLACE_MBRTOC32@
629 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
630 # undef mbrtoc32
631 # define mbrtoc32 rpl_mbrtoc32
632 # endif
633 _GL_FUNCDECL_RPL (mbrtoc32, size_t,
634 (char32_t *pc, const char *s, size_t n, mbstate_t *ps), );
635 _GL_CXXALIAS_RPL (mbrtoc32, size_t,
636 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
637 # else
638 # if !@HAVE_MBRTOC32@
639 _GL_FUNCDECL_SYS (mbrtoc32, size_t,
640 (char32_t *pc, const char *s, size_t n, mbstate_t *ps), );
641 # endif
642 _GL_CXXALIAS_SYS (mbrtoc32, size_t,
643 (char32_t *pc, const char *s, size_t n, mbstate_t *ps));
644 # endif
645 # if __GLIBC__ + (__GLIBC_MINOR__ >= 16) > 2
646 _GL_CXXALIASWARN (mbrtoc32);
647 # endif
648 #elif defined GNULIB_POSIXCHECK
649 # if HAVE_RAW_DECL_MBRTOC32
650 _GL_WARN_ON_USE (mbrtoc32, "mbrtoc32 is not portable - "
651 "use gnulib module mbrtoc32 for portability");
652 # endif
653 #endif
654
655
656 /* Converts a multibyte character and returns the next 16-bit wide
657 character. */
658 #if @GNULIB_MBRTOC16@
659 # if @REPLACE_MBRTOC16@
660 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
661 # undef mbrtoc16
662 # define mbrtoc16 rpl_mbrtoc16
663 # endif
664 _GL_FUNCDECL_RPL (mbrtoc16, size_t,
665 (char16_t *pc, const char *s, size_t n, mbstate_t *ps), );
666 _GL_CXXALIAS_RPL (mbrtoc16, size_t,
667 (char16_t *pc, const char *s, size_t n, mbstate_t *ps));
668 # else
669 # if !@HAVE_MBRTOC16@
670 _GL_FUNCDECL_SYS (mbrtoc16, size_t,
671 (char16_t *pc, const char *s, size_t n, mbstate_t *ps), );
672 # endif
673 _GL_CXXALIAS_SYS (mbrtoc16, size_t,
674 (char16_t *pc, const char *s, size_t n, mbstate_t *ps));
675 # endif
676 # if __GLIBC__ + (__GLIBC_MINOR__ >= 16) > 2
677 _GL_CXXALIASWARN (mbrtoc16);
678 # endif
679 #elif defined GNULIB_POSIXCHECK
680 # if HAVE_RAW_DECL_MBRTOC16
681 _GL_WARN_ON_USE (mbrtoc16, "mbrtoc16 is not portable - "
682 "use gnulib module mbrtoc16 for portability");
683 # endif
684 #endif
685
686
687 /* Convert a string to a 32-bit wide string. */
688 #if @GNULIB_MBSNRTOC32S@
689 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_MBSNRTOC32S
690 _GL_BEGIN_C_LINKAGE
691 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
692 mbsnrtoc32s (char32_t *dest, const char **srcp, size_t srclen, size_t len,
693 mbstate_t *ps)
694 {
695 return
696 # if @GNULIB_MBSNRTOWCS@ && defined __cplusplus && defined GNULIB_NAMESPACE
697 GNULIB_NAMESPACE::
698 # endif
699 mbsnrtowcs ((wchar_t *) dest, srcp, srclen, len, ps);
700 }
701 _GL_END_C_LINKAGE
702 # else
703 _GL_FUNCDECL_SYS (mbsnrtoc32s, size_t,
704 (char32_t *dest, const char **srcp, size_t srclen, size_t len,
705 mbstate_t *ps),
706 _GL_ARG_NONNULL ((2)));
707 # endif
708 _GL_CXXALIAS_SYS (mbsnrtoc32s, size_t,
709 (char32_t *dest, const char **srcp, size_t srclen, size_t len,
710 mbstate_t *ps));
711 _GL_CXXALIASWARN (mbsnrtoc32s);
712 #endif
713
714
715 /* Convert a string to a 32-bit wide string. */
716 #if @GNULIB_MBSRTOC32S@
717 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_MBSRTOC32S
718 _GL_BEGIN_C_LINKAGE
719 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
720 mbsrtoc32s (char32_t *dest, const char **srcp, size_t len, mbstate_t *ps)
721 {
722 return
723 # if @GNULIB_MBSRTOWCS@ && defined __cplusplus && defined GNULIB_NAMESPACE
724 GNULIB_NAMESPACE::
725 # endif
726 mbsrtowcs ((wchar_t *) dest, srcp, len, ps);
727 }
728 _GL_END_C_LINKAGE
729 # else
730 _GL_FUNCDECL_SYS (mbsrtoc32s, size_t,
731 (char32_t *dest, const char **srcp, size_t len,
732 mbstate_t *ps),
733 _GL_ARG_NONNULL ((2)));
734 # endif
735 _GL_CXXALIAS_SYS (mbsrtoc32s, size_t,
736 (char32_t *dest, const char **srcp, size_t len,
737 mbstate_t *ps));
738 _GL_CXXALIASWARN (mbsrtoc32s);
739 #endif
740
741
742 /* Convert a string to a 32-bit wide string. */
743 #if @GNULIB_MBSTOC32S@
744 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_MBSTOC32S
745 _GL_BEGIN_C_LINKAGE
746 _GL_INLINE _GL_ARG_NONNULL ((2)) size_t
747 mbstoc32s (char32_t *dest, const char *src, size_t len)
748 {
749 mbstate_t state;
750
751 mbszero (&state);
752 return mbsrtoc32s (dest, &src, len, &state);
753 }
754 _GL_END_C_LINKAGE
755 # else
756 _GL_FUNCDECL_SYS (mbstoc32s, size_t,
757 (char32_t *dest, const char *src, size_t len),
758 _GL_ARG_NONNULL ((2)));
759 # endif
760 _GL_CXXALIAS_SYS (mbstoc32s, size_t,
761 (char32_t *dest, const char *src, size_t len));
762 _GL_CXXALIASWARN (mbstoc32s);
763 #endif
764
765
766 #if @GNULIB_C32_GET_TYPE_TEST@ || @GNULIB_C32_APPLY_TYPE_TEST@
767 /* A scalar type. Instances of this type, other than (c32_type_test_t) 0,
768 represent a character property, sometimes also viewed as a "character class".
769 It can be applied to 32-bit wide characters. It is the counterpart of
770 type 'wctype_t' for wide characters.
771 To test whether a given character has a certain property, use the function
772 'c32_apply_type_test'. */
773 # if _GL_WCHAR_T_IS_UCS4
774 typedef wctype_t c32_type_test_t;
775 # else
776 typedef /*bool*/int (*c32_type_test_t) (wint_t wc);
777 # endif
778 #endif
779
780 /* Return a character property with the given name, or (c32_type_test_t) 0
781 if the designated property does not exist.
782 This function is the counterpart of function 'wctype' for wide characters.
783 */
784 #if @GNULIB_C32_GET_TYPE_TEST@
785 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32_GET_TYPE_TEST
786 _GL_BEGIN_C_LINKAGE
787 _GL_INLINE _GL_ARG_NONNULL ((1)) c32_type_test_t
788 c32_get_type_test (const char *name)
789 {
790 return
791 # if @GNULIB_WCTYPE@ && defined __cplusplus && defined GNULIB_NAMESPACE
792 GNULIB_NAMESPACE::
793 # endif
794 wctype (name);
795 }
796 _GL_END_C_LINKAGE
797 # else
798 _GL_FUNCDECL_SYS (c32_get_type_test, c32_type_test_t, (const char *name),
799 _GL_ARG_NONNULL ((1)));
800 # endif
801 _GL_CXXALIAS_SYS (c32_get_type_test, c32_type_test_t, (const char *name));
802 _GL_CXXALIASWARN (c32_get_type_test);
803 #endif
804
805 /* Test whether a given 32-bit wide character has the specified character
806 property.
807 Return non-zero if true, zero if false or if the argument is WEOF.
808 This function is the counterpart of function 'iswctype' for wide characters.
809 */
810 #if @GNULIB_C32_APPLY_TYPE_TEST@
811 # if _GL_WCHAR_T_IS_UCS4
812 # if !defined IN_C32_APPLY_TYPE_TEST
813 _GL_BEGIN_C_LINKAGE
814 _GL_INLINE int
815 c32_apply_type_test (wint_t wc, c32_type_test_t property)
816 {
817 return
818 # if @GNULIB_ISWCTYPE@ && defined __cplusplus && defined GNULIB_NAMESPACE
819 GNULIB_NAMESPACE::
820 # endif
821 iswctype (wc, property);
822 }
823 _GL_END_C_LINKAGE
824 # else
825 _GL_FUNCDECL_SYS (c32_apply_type_test, int,
826 (wint_t wc, c32_type_test_t property), );
827 # endif
828 # else
829 _GL_FUNCDECL_SYS (c32_apply_type_test, int,
830 (wint_t wc, c32_type_test_t property),
831 _GL_ARG_NONNULL ((2)));
832 # endif
833 _GL_CXXALIAS_SYS (c32_apply_type_test, int,
834 (wint_t wc, c32_type_test_t property));
835 _GL_CXXALIASWARN (c32_apply_type_test);
836 #endif
837
838
839 #if @GNULIB_C32_GET_MAPPING@ || @GNULIB_C32_APPLY_MAPPING@
840 /* A scalar type. Instances of this type, other than (c32_mapping_t) 0,
841 represent a character mapping. It can be applied to 32-bit wide characters.
842 It is the counterpart of type 'wctrans_t' for wide characters.
843 To apply a certain mapping to a given character, use the function
844 'c32_apply_mapping'. */
845 # if _GL_WCHAR_T_IS_UCS4
846 typedef wctrans_t c32_mapping_t;
847 # else
848 typedef wint_t (*c32_mapping_t) (wint_t wc);
849 # endif
850 #endif
851
852 /* Return a character mapping with the given name, or (c32_mapping_t) 0
853 if the designated mapping does not exist.
854 This function is the counterpart of function 'wctrans' for wide characters.
855 */
856 #if @GNULIB_C32_GET_MAPPING@
857 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32_GET_MAPPING
858 _GL_BEGIN_C_LINKAGE
859 _GL_INLINE _GL_ARG_NONNULL ((1)) c32_mapping_t
860 c32_get_mapping (const char *name)
861 {
862 return
863 # if @GNULIB_WCTRANS@ && defined __cplusplus && defined GNULIB_NAMESPACE
864 GNULIB_NAMESPACE::
865 # endif
866 wctrans (name);
867 }
868 _GL_END_C_LINKAGE
869 # else
870 _GL_FUNCDECL_SYS (c32_get_mapping, c32_mapping_t, (const char *name),
871 _GL_ARG_NONNULL ((1)));
872 # endif
873 _GL_CXXALIAS_SYS (c32_get_mapping, c32_mapping_t, (const char *name));
874 _GL_CXXALIASWARN (c32_get_mapping);
875 #endif
876
877 /* Apply the specified character mapping to a given 32-bit wide character.
878 Return the result of this mapping. Return the WC argument unchanged if it is
879 WEOF.
880 This function is the counterpart of function 'towctrans' for wide characters.
881 */
882 #if @GNULIB_C32_APPLY_MAPPING@
883 # if _GL_WCHAR_T_IS_UCS4 && !defined IN_C32_APPLY_MAPPING
884 _GL_BEGIN_C_LINKAGE
885 _GL_INLINE _GL_ARG_NONNULL ((2)) wint_t
886 c32_apply_mapping (wint_t wc, c32_mapping_t mapping)
887 {
888 return
889 # if @GNULIB_TOWCTRANS@ && defined __cplusplus && defined GNULIB_NAMESPACE
890 GNULIB_NAMESPACE::
891 # endif
892 towctrans (wc, mapping);
893 }
894 _GL_END_C_LINKAGE
895 # else
896 _GL_FUNCDECL_SYS (c32_apply_mapping, wint_t,
897 (wint_t wc, c32_mapping_t mapping),
898 _GL_ARG_NONNULL ((2)));
899 # endif
900 _GL_CXXALIAS_SYS (c32_apply_mapping, wint_t,
901 (wint_t wc, c32_mapping_t mapping));
902 _GL_CXXALIASWARN (c32_apply_mapping);
903 #endif
904
905
906 _GL_INLINE_HEADER_END
907
908 #endif /* _@GUARD_PREFIX@_UCHAR_H */
909 #endif /* _@GUARD_PREFIX@_UCHAR_H */