Update.
[glibc.git] / wctype / wctype.h
blobafed31e96301e24c35230b666989506ec9968470
1 /* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library 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 GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 * ISO C Standard, Amendment 1, 7.15:
21 * Wide-character classification and mapping utilities <wctype.h>
24 #ifndef _WCTYPE_H
26 #ifndef __need_iswxxx
27 # define _WCTYPE_H 1
29 # include <features.h>
30 # include <bits/types.h>
32 /* We try to get wint_t from <stddef.h>, but not all GCC versions define it
33 there. So define it ourselves if it remains undefined. */
34 # define __need_wint_t
35 # include <stddef.h>
36 # ifndef _WINT_T
37 /* Integral type unchanged by default argument promotions that can
38 hold any value corresponding to members of the extended character
39 set, as well as at least one value that does not correspond to any
40 member of the extended character set. */
41 # define _WINT_T
42 typedef unsigned int wint_t;
43 # endif
45 /* Constant expression of type `wint_t' whose value does not correspond
46 to any member of the extended character set. */
47 # ifndef WEOF
48 # define WEOF (0xffffffffu)
49 # endif
50 #endif
51 #undef __need_iswxxx
54 /* The following part is also used in the <wcsmbs.h> header when compiled
55 in the Unix98 compatibility mode. */
56 #ifndef __iswxxx_defined
57 # define __iswxxx_defined 1
59 /* Scalar type that can hold values which represent locale-specific
60 character classifications. */
61 typedef unsigned long int wctype_t;
63 # ifndef _ISwbit
64 /* The characteristics are stored always in network byte order (big
65 endian). We define the bit value interpretations here dependent on the
66 machine's byte order. */
68 # include <endian.h>
69 # if __BYTE_ORDER == __BIG_ENDIAN
70 # define _ISwbit(bit) (1 << (bit))
71 # else /* __BYTE_ORDER == __LITTLE_ENDIAN */
72 # define _ISwbit(bit) \
73 ((bit) < 8 ? (int) ((1UL << (bit)) << 24) \
74 : ((bit) < 16 ? (int) ((1UL << (bit)) << 8) \
75 : ((bit) < 24 ? (int) ((1UL << (bit)) >> 8) \
76 : (int) ((1UL << (bit)) >> 24))))
77 # endif
79 enum
81 __ISwupper = 0, /* UPPERCASE. */
82 __ISwlower = 1, /* lowercase. */
83 __ISwalpha = 2, /* Alphabetic. */
84 __ISwdigit = 3, /* Numeric. */
85 __ISwxdigit = 4, /* Hexadecimal numeric. */
86 __ISwspace = 5, /* Whitespace. */
87 __ISwprint = 6, /* Printing. */
88 __ISwgraph = 7, /* Graphical. */
89 __ISwblank = 8, /* Blank (usually SPC and TAB). */
90 __ISwcntrl = 9, /* Control character. */
91 __ISwpunct = 10, /* Punctuation. */
92 __ISwalnum = 11, /* Alphanumeric. */
94 _ISwupper = _ISwbit (__ISwupper), /* UPPERCASE. */
95 _ISwlower = _ISwbit (__ISwlower), /* lowercase. */
96 _ISwalpha = _ISwbit (__ISwalpha), /* Alphabetic. */
97 _ISwdigit = _ISwbit (__ISwdigit), /* Numeric. */
98 _ISwxdigit = _ISwbit (__ISwxdigit), /* Hexadecimal numeric. */
99 _ISwspace = _ISwbit (__ISwspace), /* Whitespace. */
100 _ISwprint = _ISwbit (__ISwprint), /* Printing. */
101 _ISwgraph = _ISwbit (__ISwgraph), /* Graphical. */
102 _ISwblank = _ISwbit (__ISwblank), /* Blank (usually SPC and TAB). */
103 _ISwcntrl = _ISwbit (__ISwcntrl), /* Control character. */
104 _ISwpunct = _ISwbit (__ISwpunct), /* Punctuation. */
105 _ISwalnum = _ISwbit (__ISwalnum) /* Alphanumeric. */
107 # endif /* Not _ISwbit */
110 __BEGIN_DECLS
113 * Wide-character classification functions: 7.15.2.1.
116 /* Test for any wide character for which `iswalpha' or `iswdigit' is
117 true. */
118 extern int iswalnum (wint_t __wc) __THROW;
120 /* Test for any wide character for which `iswupper' or 'iswlower' is
121 true, or any wide character that is one of a locale-specific set of
122 wide-characters for which none of `iswcntrl', `iswdigit',
123 `iswpunct', or `iswspace' is true. */
124 extern int iswalpha (wint_t __wc) __THROW;
126 /* Test for any control wide character. */
127 extern int iswcntrl (wint_t __wc) __THROW;
129 /* Test for any wide character that corresponds to a decimal-digit
130 character. */
131 extern int iswdigit (wint_t __wc) __THROW;
133 /* Test for any wide character for which `iswprint' is true and
134 `iswspace' is false. */
135 extern int iswgraph (wint_t __wc) __THROW;
137 /* Test for any wide character that corresponds to a lowercase letter
138 or is one of a locale-specific set of wide characters for which
139 none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
140 extern int iswlower (wint_t __wc) __THROW;
142 /* Test for any printing wide character. */
143 extern int iswprint (wint_t __wc) __THROW;
145 /* Test for any printing wide character that is one of a
146 locale-specific et of wide characters for which neither `iswspace'
147 nor `iswalnum' is true. */
148 extern int iswpunct (wint_t __wc) __THROW;
150 /* Test for any wide character that corresponds to a locale-specific
151 set of wide characters for which none of `iswalnum', `iswgraph', or
152 `iswpunct' is true. */
153 extern int iswspace (wint_t __wc) __THROW;
155 /* Test for any wide character that corresponds to an uppercase letter
156 or is one of a locale-specific set of wide character for which none
157 of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
158 extern int iswupper (wint_t __wc) __THROW;
160 /* Test for any wide character that corresponds to a hexadecimal-digit
161 character equivalent to that performed be the functions described
162 in the previous subclause. */
163 extern int iswxdigit (wint_t __wc) __THROW;
165 /* Test for any wide character that corresponds to a standard blank
166 wide character or a locale-specific set of wide characters for
167 which `iswalnum' is false. */
168 # ifdef __USE_GNU
169 extern int iswblank (wint_t __wc) __THROW;
170 # endif
173 * Extensible wide-character classification functions: 7.15.2.2.
176 /* Construct value that describes a class of wide characters identified
177 by the string argument PROPERTY. */
178 extern wctype_t __wctype (__const char *__property) __THROW;
179 extern wctype_t wctype (__const char *__property) __THROW;
181 /* Determine whether the wide-character WC has the property described by
182 DESC. */
183 extern int __iswctype (wint_t __wc, wctype_t __desc) __THROW;
184 extern int iswctype (wint_t __wc, wctype_t __desc) __THROW;
186 #if __GNUC__ >= 2 && defined __OPTIMIZE__
187 /* The tables are always organized in a way which allows direct access
188 for single byte characters. */
189 extern unsigned int *__ctype32_b;
191 # define iswalnum(wc) \
192 (__extension__ \
193 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
194 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwalnum) : iswalnum (wc)))
195 # define iswalpha(wc) \
196 (__extension__ \
197 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
198 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwalpha) : iswalpha (wc)))
199 # define iswcntrl(wc) \
200 (__extension__ \
201 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
202 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwcntrl) : iswcntrl (wc)))
203 # define iswdigit(wc) \
204 (__extension__ \
205 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
206 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwdigit) : iswdigit (wc)))
207 # define iswlower(wc) \
208 (__extension__ \
209 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
210 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwlower) : iswlower (wc)))
211 # define iswgraph(wc) \
212 (__extension__ \
213 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
214 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwgraph) : iswgraph (wc)))
215 # define iswprint(wc) \
216 (__extension__ \
217 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
218 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwprint) : iswprint (wc)))
219 # define iswpunct(wc) \
220 (__extension__ \
221 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
222 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwpunct) : iswpunct (wc)))
223 # define iswspace(wc) \
224 (__extension__ \
225 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
226 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwspace) : iswspace (wc)))
227 # define iswupper(wc) \
228 (__extension__ \
229 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
230 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwupper) : iswupper (wc)))
231 # define iswxdigit(wc) \
232 (__extension__ \
233 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
234 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwxdigit) : iswxdigit (wc)))
236 # ifdef __USE_GNU
237 # define iswblank(wc) \
238 (__extension__ \
239 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
240 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwblank) : iswblank (wc)))
241 # endif
243 #endif /* gcc && optimizing */
246 * Wide-character case-mapping functions: 7.15.3.1.
249 /* Scalar type that can hold values which represent locale-specific
250 character mappings. */
251 typedef __const __int32_t *wctrans_t;
253 /* Converts an uppercase letter to the corresponding lowercase letter. */
254 extern wint_t towlower (wint_t __wc) __THROW;
256 /* Converts an lowercase letter to the corresponding uppercase letter. */
257 extern wint_t towupper (wint_t __wc) __THROW;
259 /* Map the wide character WC using the mapping described by DESC. */
260 extern wint_t __towctrans (wint_t __wc, wctrans_t __desc) __THROW;
262 #if __GNUC__ >= 2 && defined __OPTIMIZE__
263 /* The tables are always organized in a way which allows direct access
264 for single byte characters. */
265 extern const wint_t *__ctype32_tolower;
266 extern const wint_t *__ctype32_toupper;
268 # define towlower(wc) \
269 (__extension__ \
270 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
271 ? (wint_t) __ctype32_tolower[(wint_t) (wc)] : towlower (wc)))
273 # define towupper(wc) \
274 (__extension__ \
275 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
276 ? (wint_t) __ctype32_toupper[(wint_t) (wc)] : towupper (wc)))
278 #endif /* gcc && optimizing */
280 __END_DECLS
282 #endif /* need iswxxx. */
285 /* The remaining definitions and declarations must not appear in the
286 <wcsmbs.h> header. */
287 #ifdef _WCTYPE_H
290 * Extensible wide-character mapping functions: 7.15.3.2.
293 __BEGIN_DECLS
295 /* Construct value that describes a mapping between wide characters
296 identified by the string argument PROPERTY. */
297 extern wctrans_t wctrans (__const char *__property) __THROW;
299 /* Map the wide character WC using the mapping described by DESC. */
300 extern wint_t towctrans (wint_t __wc, wctrans_t __desc) __THROW;
302 # ifdef __USE_GNU
303 /* Declare the interface to extended locale model. */
304 # include <xlocale.h>
306 /* Test for any wide character for which `iswalpha' or `iswdigit' is
307 true. */
308 extern int __iswalnum_l (wint_t __wc, __locale_t __locale) __THROW;
310 /* Test for any wide character for which `iswupper' or 'iswlower' is
311 true, or any wide character that is one of a locale-specific set of
312 wide-characters for which none of `iswcntrl', `iswdigit',
313 `iswpunct', or `iswspace' is true. */
314 extern int __iswalpha_l (wint_t __wc, __locale_t __locale) __THROW;
316 /* Test for any control wide character. */
317 extern int __iswcntrl_l (wint_t __wc, __locale_t __locale) __THROW;
319 /* Test for any wide character that corresponds to a decimal-digit
320 character. */
321 extern int __iswdigit_l (wint_t __wc, __locale_t __locale) __THROW;
323 /* Test for any wide character for which `iswprint' is true and
324 `iswspace' is false. */
325 extern int __iswgraph_l (wint_t __wc, __locale_t __locale) __THROW;
327 /* Test for any wide character that corresponds to a lowercase letter
328 or is one of a locale-specific set of wide characters for which
329 none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
330 extern int __iswlower_l (wint_t __wc, __locale_t __locale) __THROW;
332 /* Test for any printing wide character. */
333 extern int __iswprint_l (wint_t __wc, __locale_t __locale) __THROW;
335 /* Test for any printing wide character that is one of a
336 locale-specific et of wide characters for which neither `iswspace'
337 nor `iswalnum' is true. */
338 extern int __iswpunct_l (wint_t __wc, __locale_t __locale) __THROW;
340 /* Test for any wide character that corresponds to a locale-specific
341 set of wide characters for which none of `iswalnum', `iswgraph', or
342 `iswpunct' is true. */
343 extern int __iswspace_l (wint_t __wc, __locale_t __locale) __THROW;
345 /* Test for any wide character that corresponds to an uppercase letter
346 or is one of a locale-specific set of wide character for which none
347 of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
348 extern int __iswupper_l (wint_t __wc, __locale_t __locale) __THROW;
350 /* Test for any wide character that corresponds to a hexadecimal-digit
351 character equivalent to that performed be the functions described
352 in the previous subclause. */
353 extern int __iswxdigit_l (wint_t __wc, __locale_t __locale) __THROW;
355 /* Test for any wide character that corresponds to a standard blank
356 wide character or a locale-specific set of wide characters for
357 which `iswalnum' is false. */
358 extern int __iswblank_l (wint_t __wc, __locale_t __locale) __THROW;
360 /* Construct value that describes a class of wide characters identified
361 by the string argument PROPERTY. */
362 extern wctype_t __wctype_l (__const char *__property, __locale_t __locale)
363 __THROW;
365 /* Determine whether the wide-character WC has the property described by
366 DESC. */
367 extern int __iswctype_l (wint_t __wc, wctype_t __desc, __locale_t __locale)
368 __THROW;
372 * Wide-character case-mapping functions.
375 /* Converts an uppercase letter to the corresponding lowercase letter. */
376 extern wint_t __towlower_l (wint_t __wc, __locale_t __locale) __THROW;
378 /* Converts an lowercase letter to the corresponding uppercase letter. */
379 extern wint_t __towupper_l (wint_t __wc, __locale_t __locale) __THROW;
381 /* Construct value that describes a mapping between wide characters
382 identified by the string argument PROPERTY. */
383 extern wctrans_t __wctrans_l (__const char *__property, __locale_t __locale)
384 __THROW;
386 /* Map the wide character WC using the mapping described by DESC. */
387 extern wint_t __towctrans_l (wint_t __wc, wctrans_t __desc,
388 __locale_t __locale) __THROW;
390 # endif /* Use GNU. */
392 __END_DECLS
394 #endif /* __WCTYPE_H defined. */
396 #endif /* wctype.h */