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
26 @PRAGMA_SYSTEM_HEADER@
31 # @INCLUDE_NEXT@ @NEXT_UCHAR_H@
34 /* Get uint_least16_t, uint_least32_t. */
37 /* Get mbstate_t, size_t. */
40 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
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 #elif @GNULIB_OVERRIDES_CHAR16_T@
52 typedef uint_least16_t gl_char16_t
;
53 # define char16_t gl_char16_t
59 /* A 32-bit variant of wchar_t.
60 Note: This type does *NOT* denote UTF-32 code points. (Only on platforms
61 on which __STDC_UTF_32__ is defined.) */
62 typedef uint_least32_t char32_t
;
64 #elif @GNULIB_OVERRIDES_CHAR32_T@
66 typedef uint_least32_t gl_char32_t
;
67 # define char32_t gl_char32_t
71 /* Define if a 'char32_t' can hold more characters than a 'wchar_t'. */
72 #if @SMALL_WCHAR_T@ /* 32-bit AIX, Cygwin, native Windows */
73 # define _GL_LARGE_CHAR32_T 1
77 /* Convert a single-byte character to a 32-bit wide character. */
79 _GL_FUNCDECL_SYS (btoc32
, wint_t, (int c
) _GL_ATTRIBUTE_PURE
);
80 _GL_CXXALIAS_SYS (btoc32
, wint_t, (int c
));
81 _GL_CXXALIASWARN (btoc32
);
85 /* Test a specific property of a 32-bit wide character. */
86 #if @GNULIB_C32ISALNUM@
87 _GL_FUNCDECL_SYS (c32isalnum
, int, (wint_t wc
));
88 _GL_CXXALIAS_SYS (c32isalnum
, int, (wint_t wc
));
89 _GL_CXXALIASWARN (c32isalnum
);
91 #if @GNULIB_C32ISALPHA@
92 _GL_FUNCDECL_SYS (c32isalpha
, int, (wint_t wc
));
93 _GL_CXXALIAS_SYS (c32isalpha
, int, (wint_t wc
));
94 _GL_CXXALIASWARN (c32isalpha
);
96 #if @GNULIB_C32ISBLANK@
97 _GL_FUNCDECL_SYS (c32isblank
, int, (wint_t wc
));
98 _GL_CXXALIAS_SYS (c32isblank
, int, (wint_t wc
));
99 _GL_CXXALIASWARN (c32isblank
);
101 #if @GNULIB_C32ISCNTRL@
102 _GL_FUNCDECL_SYS (c32iscntrl
, int, (wint_t wc
));
103 _GL_CXXALIAS_SYS (c32iscntrl
, int, (wint_t wc
));
104 _GL_CXXALIASWARN (c32iscntrl
);
106 #if @GNULIB_C32ISDIGIT@
107 _GL_FUNCDECL_SYS (c32isdigit
, int, (wint_t wc
));
108 _GL_CXXALIAS_SYS (c32isdigit
, int, (wint_t wc
));
109 _GL_CXXALIASWARN (c32isdigit
);
111 #if @GNULIB_C32ISGRAPH@
112 _GL_FUNCDECL_SYS (c32isgraph
, int, (wint_t wc
));
113 _GL_CXXALIAS_SYS (c32isgraph
, int, (wint_t wc
));
114 _GL_CXXALIASWARN (c32isgraph
);
116 #if @GNULIB_C32ISLOWER@
117 _GL_FUNCDECL_SYS (c32islower
, int, (wint_t wc
));
118 _GL_CXXALIAS_SYS (c32islower
, int, (wint_t wc
));
119 _GL_CXXALIASWARN (c32islower
);
121 #if @GNULIB_C32ISPRINT@
122 _GL_FUNCDECL_SYS (c32isprint
, int, (wint_t wc
));
123 _GL_CXXALIAS_SYS (c32isprint
, int, (wint_t wc
));
124 _GL_CXXALIASWARN (c32isprint
);
126 #if @GNULIB_C32ISPUNCT@
127 _GL_FUNCDECL_SYS (c32ispunct
, int, (wint_t wc
));
128 _GL_CXXALIAS_SYS (c32ispunct
, int, (wint_t wc
));
129 _GL_CXXALIASWARN (c32ispunct
);
131 #if @GNULIB_C32ISSPACE@
132 _GL_FUNCDECL_SYS (c32isspace
, int, (wint_t wc
));
133 _GL_CXXALIAS_SYS (c32isspace
, int, (wint_t wc
));
134 _GL_CXXALIASWARN (c32isspace
);
136 #if @GNULIB_C32ISUPPER@
137 _GL_FUNCDECL_SYS (c32isupper
, int, (wint_t wc
));
138 _GL_CXXALIAS_SYS (c32isupper
, int, (wint_t wc
));
139 _GL_CXXALIASWARN (c32isupper
);
141 #if @GNULIB_C32ISXDIGIT@
142 _GL_FUNCDECL_SYS (c32isxdigit
, int, (wint_t wc
));
143 _GL_CXXALIAS_SYS (c32isxdigit
, int, (wint_t wc
));
144 _GL_CXXALIASWARN (c32isxdigit
);
148 /* Converts a 32-bit wide character to a multibyte character. */
149 #if @GNULIB_C32RTOMB@
150 # if @REPLACE_C32RTOMB@
151 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
153 # define c32rtomb rpl_c32rtomb
155 _GL_FUNCDECL_RPL (c32rtomb
, size_t, (char *s
, char32_t wc
, mbstate_t *ps
));
156 _GL_CXXALIAS_RPL (c32rtomb
, size_t, (char *s
, char32_t wc
, mbstate_t *ps
));
158 # if !@HAVE_C32RTOMB@
159 _GL_FUNCDECL_SYS (c32rtomb
, size_t, (char *s
, char32_t wc
, mbstate_t *ps
));
161 _GL_CXXALIAS_SYS (c32rtomb
, size_t, (char *s
, char32_t wc
, mbstate_t *ps
));
163 _GL_CXXALIASWARN (c32rtomb
);
164 #elif defined GNULIB_POSIXCHECK
166 # if HAVE_RAW_DECL_C32RTOMB
167 _GL_WARN_ON_USE (mbrtoc32
, "c32rtomb is not portable - "
168 "use gnulib module c32rtomb for portability");
173 /* Convert a 32-bit wide string to a string. */
174 #if @GNULIB_C32SNRTOMBS@
175 _GL_FUNCDECL_SYS (c32snrtombs
, size_t,
176 (char *dest
, const char32_t
**srcp
, size_t srclen
, size_t len
,
178 _GL_ARG_NONNULL ((2)));
179 _GL_CXXALIAS_SYS (c32snrtombs
, size_t,
180 (char *dest
, const char32_t
**srcp
, size_t srclen
, size_t len
,
182 _GL_CXXALIASWARN (c32snrtombs
);
186 /* Convert a 32-bit wide string to a string. */
187 #if @GNULIB_C32SRTOMBS@
188 _GL_FUNCDECL_SYS (c32srtombs
, size_t,
189 (char *dest
, const char32_t
**srcp
, size_t len
, mbstate_t *ps
)
190 _GL_ARG_NONNULL ((2)));
191 _GL_CXXALIAS_SYS (c32srtombs
, size_t,
192 (char *dest
, const char32_t
**srcp
, size_t len
,
194 _GL_CXXALIASWARN (c32srtombs
);
198 /* Convert a 32-bit wide string to a string. */
199 #if @GNULIB_C32STOMBS@
200 _GL_FUNCDECL_SYS (c32stombs
, size_t,
201 (char *dest
, const char32_t
*src
, size_t len
)
202 _GL_ARG_NONNULL ((2)));
203 _GL_CXXALIAS_SYS (c32stombs
, size_t,
204 (char *dest
, const char32_t
*src
, size_t len
));
205 _GL_CXXALIASWARN (c32stombs
);
209 /* Converts a 32-bit wide character to unibyte character.
210 Returns the single-byte representation of WC if it exists,
213 _GL_FUNCDECL_SYS (c32tob
, int, (wint_t wc
));
214 _GL_CXXALIAS_SYS (c32tob
, int, (wint_t wc
));
215 _GL_CXXALIASWARN (c32tob
);
219 /* Converts a multibyte character to a 32-bit wide character. */
220 #if @GNULIB_MBRTOC32@
221 # if @REPLACE_MBRTOC32@
222 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
224 # define mbrtoc32 rpl_mbrtoc32
226 _GL_FUNCDECL_RPL (mbrtoc32
, size_t,
227 (char32_t
*pc
, const char *s
, size_t n
, mbstate_t *ps
));
228 _GL_CXXALIAS_RPL (mbrtoc32
, size_t,
229 (char32_t
*pc
, const char *s
, size_t n
, mbstate_t *ps
));
231 # if !@HAVE_MBRTOC32@
232 _GL_FUNCDECL_SYS (mbrtoc32
, size_t,
233 (char32_t
*pc
, const char *s
, size_t n
, mbstate_t *ps
));
235 _GL_CXXALIAS_SYS (mbrtoc32
, size_t,
236 (char32_t
*pc
, const char *s
, size_t n
, mbstate_t *ps
));
238 _GL_CXXALIASWARN (mbrtoc32
);
239 #elif defined GNULIB_POSIXCHECK
241 # if HAVE_RAW_DECL_MBRTOC32
242 _GL_WARN_ON_USE (mbrtoc32
, "mbrtoc32 is not portable - "
243 "use gnulib module mbrtoc32 for portability");
248 /* Convert a string to a 32-bit wide string. */
249 #if @GNULIB_MBSNRTOC32S@
250 _GL_FUNCDECL_SYS (mbsnrtoc32s
, size_t,
251 (char32_t
*dest
, const char **srcp
, size_t srclen
, size_t len
,
253 _GL_ARG_NONNULL ((2)));
254 _GL_CXXALIAS_SYS (mbsnrtoc32s
, size_t,
255 (char32_t
*dest
, const char **srcp
, size_t srclen
, size_t len
,
257 _GL_CXXALIASWARN (mbsnrtoc32s
);
261 /* Convert a string to a 32-bit wide string. */
262 #if @GNULIB_MBSRTOC32S@
263 _GL_FUNCDECL_SYS (mbsrtoc32s
, size_t,
264 (char32_t
*dest
, const char **srcp
, size_t len
, mbstate_t *ps
)
265 _GL_ARG_NONNULL ((2)));
266 _GL_CXXALIAS_SYS (mbsrtoc32s
, size_t,
267 (char32_t
*dest
, const char **srcp
, size_t len
,
269 _GL_CXXALIASWARN (mbsrtoc32s
);
273 /* Convert a string to a 32-bit wide string. */
274 #if @GNULIB_MBSTOC32S@
275 _GL_FUNCDECL_SYS (mbstoc32s
, size_t,
276 (char32_t
*dest
, const char *src
, size_t len
)
277 _GL_ARG_NONNULL ((2)));
278 _GL_CXXALIAS_SYS (mbstoc32s
, size_t,
279 (char32_t
*dest
, const char *src
, size_t len
));
280 _GL_CXXALIASWARN (mbstoc32s
);
284 #endif /* _@GUARD_PREFIX@_UCHAR_H */