Update.
[glibc.git] / wctype / wctype.h
blob0ef675c0f93a26271a82c1413080a9d939a91903
1 /* Copyright (C) 1996,1997,1998,1999,2000,2001 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 C99 Standard: 7.25
21 * Wide character classification and mapping utilities <wctype.h>
24 #ifndef _WCTYPE_H
26 #include <features.h>
27 #include <bits/types.h>
29 #ifndef __need_iswxxx
30 # define _WCTYPE_H 1
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_ISOC99
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;
180 /* Determine whether the wide-character WC has the property described by
181 DESC. */
182 extern int iswctype (wint_t __wc, wctype_t __desc) __THROW;
184 #if __GNUC__ >= 2 && defined __OPTIMIZE__
185 /* The tables are always organized in a way which allows direct access
186 for single byte characters. */
187 extern unsigned int *__ctype32_b;
189 # define iswalnum(wc) \
190 (__extension__ \
191 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
192 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwalnum) : iswalnum (wc)))
193 # define iswalpha(wc) \
194 (__extension__ \
195 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
196 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwalpha) : iswalpha (wc)))
197 # define iswcntrl(wc) \
198 (__extension__ \
199 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
200 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwcntrl) : iswcntrl (wc)))
201 # define iswdigit(wc) \
202 (__extension__ \
203 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
204 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwdigit) : iswdigit (wc)))
205 # define iswlower(wc) \
206 (__extension__ \
207 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
208 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwlower) : iswlower (wc)))
209 # define iswgraph(wc) \
210 (__extension__ \
211 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
212 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwgraph) : iswgraph (wc)))
213 # define iswprint(wc) \
214 (__extension__ \
215 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
216 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwprint) : iswprint (wc)))
217 # define iswpunct(wc) \
218 (__extension__ \
219 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
220 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwpunct) : iswpunct (wc)))
221 # define iswspace(wc) \
222 (__extension__ \
223 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
224 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwspace) : iswspace (wc)))
225 # define iswupper(wc) \
226 (__extension__ \
227 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
228 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwupper) : iswupper (wc)))
229 # define iswxdigit(wc) \
230 (__extension__ \
231 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
232 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwxdigit) : iswxdigit (wc)))
234 # ifdef __USE_ISOC99
235 # define iswblank(wc) \
236 (__extension__ \
237 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
238 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwblank) : iswblank (wc)))
239 # endif
241 #endif /* gcc && optimizing */
244 * Wide-character case-mapping functions: 7.15.3.1.
247 /* Scalar type that can hold values which represent locale-specific
248 character mappings. */
249 typedef __const __int32_t *wctrans_t;
251 /* Converts an uppercase letter to the corresponding lowercase letter. */
252 extern wint_t towlower (wint_t __wc) __THROW;
254 /* Converts an lowercase letter to the corresponding uppercase letter. */
255 extern wint_t towupper (wint_t __wc) __THROW;
257 #if __GNUC__ >= 2 && defined __OPTIMIZE__
258 /* The tables are always organized in a way which allows direct access
259 for single byte characters. */
260 extern const wint_t *__ctype32_tolower;
261 extern const wint_t *__ctype32_toupper;
263 # define towlower(wc) \
264 (__extension__ \
265 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
266 ? (wint_t) __ctype32_tolower[(wint_t) (wc)] : towlower (wc)))
268 # define towupper(wc) \
269 (__extension__ \
270 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
271 ? (wint_t) __ctype32_toupper[(wint_t) (wc)] : towupper (wc)))
273 #endif /* gcc && optimizing */
275 __END_DECLS
277 #endif /* need iswxxx. */
280 /* The remaining definitions and declarations must not appear in the
281 <wcsmbs.h> header. */
282 #ifdef _WCTYPE_H
285 * Extensible wide-character mapping functions: 7.15.3.2.
288 __BEGIN_DECLS
290 /* Construct value that describes a mapping between wide characters
291 identified by the string argument PROPERTY. */
292 extern wctrans_t wctrans (__const char *__property) __THROW;
294 /* Map the wide character WC using the mapping described by DESC. */
295 extern wint_t towctrans (wint_t __wc, wctrans_t __desc) __THROW;
297 # ifdef __USE_GNU
298 /* Declare the interface to extended locale model. */
299 # include <xlocale.h>
301 /* Test for any wide character for which `iswalpha' or `iswdigit' is
302 true. */
303 extern int __iswalnum_l (wint_t __wc, __locale_t __locale) __THROW;
305 /* Test for any wide character for which `iswupper' or 'iswlower' is
306 true, or any wide character that is one of a locale-specific set of
307 wide-characters for which none of `iswcntrl', `iswdigit',
308 `iswpunct', or `iswspace' is true. */
309 extern int __iswalpha_l (wint_t __wc, __locale_t __locale) __THROW;
311 /* Test for any control wide character. */
312 extern int __iswcntrl_l (wint_t __wc, __locale_t __locale) __THROW;
314 /* Test for any wide character that corresponds to a decimal-digit
315 character. */
316 extern int __iswdigit_l (wint_t __wc, __locale_t __locale) __THROW;
318 /* Test for any wide character for which `iswprint' is true and
319 `iswspace' is false. */
320 extern int __iswgraph_l (wint_t __wc, __locale_t __locale) __THROW;
322 /* Test for any wide character that corresponds to a lowercase letter
323 or is one of a locale-specific set of wide characters for which
324 none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
325 extern int __iswlower_l (wint_t __wc, __locale_t __locale) __THROW;
327 /* Test for any printing wide character. */
328 extern int __iswprint_l (wint_t __wc, __locale_t __locale) __THROW;
330 /* Test for any printing wide character that is one of a
331 locale-specific et of wide characters for which neither `iswspace'
332 nor `iswalnum' is true. */
333 extern int __iswpunct_l (wint_t __wc, __locale_t __locale) __THROW;
335 /* Test for any wide character that corresponds to a locale-specific
336 set of wide characters for which none of `iswalnum', `iswgraph', or
337 `iswpunct' is true. */
338 extern int __iswspace_l (wint_t __wc, __locale_t __locale) __THROW;
340 /* Test for any wide character that corresponds to an uppercase letter
341 or is one of a locale-specific set of wide character for which none
342 of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
343 extern int __iswupper_l (wint_t __wc, __locale_t __locale) __THROW;
345 /* Test for any wide character that corresponds to a hexadecimal-digit
346 character equivalent to that performed be the functions described
347 in the previous subclause. */
348 extern int __iswxdigit_l (wint_t __wc, __locale_t __locale) __THROW;
350 /* Test for any wide character that corresponds to a standard blank
351 wide character or a locale-specific set of wide characters for
352 which `iswalnum' is false. */
353 extern int __iswblank_l (wint_t __wc, __locale_t __locale) __THROW;
355 /* Construct value that describes a class of wide characters identified
356 by the string argument PROPERTY. */
357 extern wctype_t __wctype_l (__const char *__property, __locale_t __locale)
358 __THROW;
360 /* Determine whether the wide-character WC has the property described by
361 DESC. */
362 extern int __iswctype_l (wint_t __wc, wctype_t __desc, __locale_t __locale)
363 __THROW;
367 * Wide-character case-mapping functions.
370 /* Converts an uppercase letter to the corresponding lowercase letter. */
371 extern wint_t __towlower_l (wint_t __wc, __locale_t __locale) __THROW;
373 /* Converts an lowercase letter to the corresponding uppercase letter. */
374 extern wint_t __towupper_l (wint_t __wc, __locale_t __locale) __THROW;
376 /* Construct value that describes a mapping between wide characters
377 identified by the string argument PROPERTY. */
378 extern wctrans_t __wctrans_l (__const char *__property, __locale_t __locale)
379 __THROW;
381 /* Map the wide character WC using the mapping described by DESC. */
382 extern wint_t __towctrans_l (wint_t __wc, wctrans_t __desc,
383 __locale_t __locale) __THROW;
385 # endif /* Use GNU. */
387 __END_DECLS
389 #endif /* __WCTYPE_H defined. */
391 #endif /* wctype.h */