Update.
[glibc.git] / wctype / wctype.h
blob2a4caddd901136dbd941095595b341fd6b340027
1 /* Copyright (C) 1996, 1997, 1998, 1999 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 = _ISwbit (0), /* UPPERCASE. */
82 _ISwlower = _ISwbit (1), /* lowercase. */
83 _ISwalpha = _ISwbit (2), /* Alphabetic. */
84 _ISwdigit = _ISwbit (3), /* Numeric. */
85 _ISwxdigit = _ISwbit (4), /* Hexadecimal numeric. */
86 _ISwspace = _ISwbit (5), /* Whitespace. */
87 _ISwprint = _ISwbit (6), /* Printing. */
88 _ISwgraph = _ISwbit (7), /* Graphical. */
89 _ISwblank = _ISwbit (8), /* Blank (usually SPC and TAB). */
90 _ISwcntrl = _ISwbit (9), /* Control character. */
91 _ISwpunct = _ISwbit (10), /* Punctuation. */
92 _ISwalnum = _ISwbit (11) /* Alphanumeric. */
94 # endif /* Not _ISwbit */
97 __BEGIN_DECLS
100 * Wide-character classification functions: 7.15.2.1.
103 /* Test for any wide character for which `iswalpha' or `iswdigit' is
104 true. */
105 extern int iswalnum (wint_t __wc) __THROW;
107 /* Test for any wide character for which `iswupper' or 'iswlower' is
108 true, or any wide character that is one of a locale-specific set of
109 wide-characters for which none of `iswcntrl', `iswdigit',
110 `iswpunct', or `iswspace' is true. */
111 extern int iswalpha (wint_t __wc) __THROW;
113 /* Test for any control wide character. */
114 extern int iswcntrl (wint_t __wc) __THROW;
116 /* Test for any wide character that corresponds to a decimal-digit
117 character. */
118 extern int iswdigit (wint_t __wc) __THROW;
120 /* Test for any wide character for which `iswprint' is true and
121 `iswspace' is false. */
122 extern int iswgraph (wint_t __wc) __THROW;
124 /* Test for any wide character that corresponds to a lowercase letter
125 or is one of a locale-specific set of wide characters for which
126 none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
127 extern int iswlower (wint_t __wc) __THROW;
129 /* Test for any printing wide character. */
130 extern int iswprint (wint_t __wc) __THROW;
132 /* Test for any printing wide character that is one of a
133 locale-specific et of wide characters for which neither `iswspace'
134 nor `iswalnum' is true. */
135 extern int iswpunct (wint_t __wc) __THROW;
137 /* Test for any wide character that corresponds to a locale-specific
138 set of wide characters for which none of `iswalnum', `iswgraph', or
139 `iswpunct' is true. */
140 extern int iswspace (wint_t __wc) __THROW;
142 /* Test for any wide character that corresponds to an uppercase letter
143 or is one of a locale-specific set of wide character for which none
144 of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
145 extern int iswupper (wint_t __wc) __THROW;
147 /* Test for any wide character that corresponds to a hexadecimal-digit
148 character equivalent to that performed be the functions described
149 in the previous subclause. */
150 extern int iswxdigit (wint_t __wc) __THROW;
152 /* Test for any wide character that corresponds to a standard blank
153 wide character or a locale-specific set of wide characters for
154 which `iswalnum' is false. */
155 # ifdef __USE_GNU
156 extern int iswblank (wint_t __wc) __THROW;
157 # endif
160 * Extensible wide-character classification functions: 7.15.2.2.
163 /* Construct value that describes a class of wide characters identified
164 by the string argument PROPERTY. */
165 extern wctype_t __wctype (__const char *__property) __THROW;
166 extern wctype_t wctype (__const char *__property) __THROW;
168 /* Determine whether the wide-character WC has the property described by
169 DESC. */
170 extern int __iswctype (wint_t __wc, wctype_t __desc) __THROW;
171 extern int iswctype (wint_t __wc, wctype_t __desc) __THROW;
173 #if __GNUC__ >= 2 && defined __OPTIMIZE__
174 /* The tables are always organized in a way which allows direct access
175 for single byte characters. */
176 extern unsigned int *__ctype32_b;
178 # define iswalnum(wc) \
179 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
180 ? (int) (__ctype32_b[wc] & _ISwalnum) : iswalnum (wc))
181 # define iswalpha(wc) \
182 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
183 ? (int) (__ctype32_b[wc] & _ISwalpha) : iswalpha (wc))
184 # define iswcntrl(wc) \
185 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
186 ? (int) (__ctype32_b[wc] & _ISwcntrl) : iswcntrl (wc))
187 # define iswdigit(wc) \
188 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
189 ? (int) (__ctype32_b[wc] & _ISwdigit) : iswdigit (wc))
190 # define iswlower(wc) \
191 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
192 ? (int) (__ctype32_b[wc] & _ISwlower) : iswlower (wc))
193 # define iswgraph(wc) \
194 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
195 ? (int) (__ctype32_b[wc] & _ISwgraph) : iswgraph (wc))
196 # define iswprint(wc) \
197 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
198 ? (int) (__ctype32_b[wc] & _ISwprint) : iswprint (wc))
199 # define iswpunct(wc) \
200 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
201 ? (int) (__ctype32_b[wc] & _ISwpunct) : iswpunct (wc))
202 # define iswspace(wc) \
203 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
204 ? (int) (__ctype32_b[wc] & _ISwspace) : iswspace (wc))
205 # define iswupper(wc) \
206 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
207 ? (int) (__ctype32_b[wc] & _ISwupper) : iswupper (wc))
208 # define iswxdigit(wc) \
209 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
210 ? (int) (__ctype32_b[wc] & _ISwxdigit) : iswxdigit (wc))
212 # ifdef __USE_GNU
213 # define iswblank(wc) \
214 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
215 ? (int) (__ctype32_b[wc] & _ISwblank) : iswblank (wc))
216 # endif
218 # define iswctype(wc, desc) \
219 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
220 ? (int) (__ctype32_b[wc] & desc) : iswctype (wc, desc))
222 #endif /* gcc && optimizing */
225 * Wide-character case-mapping functions: 7.15.3.1.
228 /* Scalar type that can hold values which represent locale-specific
229 character mappings. */
230 typedef __const __int32_t *wctrans_t;
232 /* Converts an uppercase letter to the corresponding lowercase letter. */
233 extern wint_t towlower (wint_t __wc) __THROW;
235 /* Converts an lowercase letter to the corresponding uppercase letter. */
236 extern wint_t towupper (wint_t __wc) __THROW;
238 /* Map the wide character WC using the mapping described by DESC. */
239 extern wint_t __towctrans (wint_t __wc, wctrans_t __desc) __THROW;
241 #if __GNUC__ >= 2 && defined __OPTIMIZE__
242 /* The tables are always organized in a way which allows direct access
243 for single byte characters. */
244 extern const wint_t *__ctype32_tolower;
245 extern const wint_t *__ctype32_toupper;
247 # define towlower(wc) \
248 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
249 ? (wint_t) __ctype32_tolower[wc] : towlower (wc))
251 # define towupper(wc) \
252 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
253 ? (wint_t) __ctype32_toupper[wc] : towupper (wc))
255 #endif /* gcc && optimizing */
257 __END_DECLS
259 #endif /* need iswxxx. */
262 /* The remaining definitions and declarations must not appear in the
263 <wcsmbs.h> header. */
264 #ifdef _WCTYPE_H
267 * Extensible wide-character mapping functions: 7.15.3.2.
270 __BEGIN_DECLS
272 /* Construct value that describes a mapping between wide characters
273 identified by the string argument PROPERTY. */
274 extern wctrans_t wctrans (__const char *__property) __THROW;
276 /* Map the wide character WC using the mapping described by DESC. */
277 extern wint_t towctrans (wint_t __wc, wctrans_t __desc) __THROW;
279 # ifdef __USE_GNU
280 /* Declare the interface to extended locale model. */
281 # include <xlocale.h>
283 /* Test for any wide character for which `iswalpha' or `iswdigit' is
284 true. */
285 extern int __iswalnum_l (wint_t __wc, __locale_t __locale) __THROW;
287 /* Test for any wide character for which `iswupper' or 'iswlower' is
288 true, or any wide character that is one of a locale-specific set of
289 wide-characters for which none of `iswcntrl', `iswdigit',
290 `iswpunct', or `iswspace' is true. */
291 extern int __iswalpha_l (wint_t __wc, __locale_t __locale) __THROW;
293 /* Test for any control wide character. */
294 extern int __iswcntrl_l (wint_t __wc, __locale_t __locale) __THROW;
296 /* Test for any wide character that corresponds to a decimal-digit
297 character. */
298 extern int __iswdigit_l (wint_t __wc, __locale_t __locale) __THROW;
300 /* Test for any wide character for which `iswprint' is true and
301 `iswspace' is false. */
302 extern int __iswgraph_l (wint_t __wc, __locale_t __locale) __THROW;
304 /* Test for any wide character that corresponds to a lowercase letter
305 or is one of a locale-specific set of wide characters for which
306 none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
307 extern int __iswlower_l (wint_t __wc, __locale_t __locale) __THROW;
309 /* Test for any printing wide character. */
310 extern int __iswprint_l (wint_t __wc, __locale_t __locale) __THROW;
312 /* Test for any printing wide character that is one of a
313 locale-specific et of wide characters for which neither `iswspace'
314 nor `iswalnum' is true. */
315 extern int __iswpunct_l (wint_t __wc, __locale_t __locale) __THROW;
317 /* Test for any wide character that corresponds to a locale-specific
318 set of wide characters for which none of `iswalnum', `iswgraph', or
319 `iswpunct' is true. */
320 extern int __iswspace_l (wint_t __wc, __locale_t __locale) __THROW;
322 /* Test for any wide character that corresponds to an uppercase letter
323 or is one of a locale-specific set of wide character for which none
324 of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
325 extern int __iswupper_l (wint_t __wc, __locale_t __locale) __THROW;
327 /* Test for any wide character that corresponds to a hexadecimal-digit
328 character equivalent to that performed be the functions described
329 in the previous subclause. */
330 extern int __iswxdigit_l (wint_t __wc, __locale_t __locale) __THROW;
332 /* Test for any wide character that corresponds to a standard blank
333 wide character or a locale-specific set of wide characters for
334 which `iswalnum' is false. */
335 extern int __iswblank_l (wint_t __wc, __locale_t __locale) __THROW;
337 /* Construct value that describes a class of wide characters identified
338 by the string argument PROPERTY. */
339 extern wctype_t __wctype_l (__const char *__property, __locale_t __locale)
340 __THROW;
342 /* Determine whether the wide-character WC has the property described by
343 DESC. */
344 extern int __iswctype_l (wint_t __wc, wctype_t __desc, __locale_t __locale)
345 __THROW;
349 * Wide-character case-mapping functions.
352 /* Converts an uppercase letter to the corresponding lowercase letter. */
353 extern wint_t __towlower_l (wint_t __wc, __locale_t __locale) __THROW;
355 /* Converts an lowercase letter to the corresponding uppercase letter. */
356 extern wint_t __towupper_l (wint_t __wc, __locale_t __locale) __THROW;
358 /* Map the wide character WC using the mapping described by DESC. */
359 extern wint_t __towctrans_l (wint_t __wc, wctrans_t __desc,
360 __locale_t __locale) __THROW;
362 # endif /* Use GNU. */
364 __END_DECLS
366 #endif /* __WCTYPE_H defined. */
368 #endif /* wctype.h */