Update.
[glibc.git] / wctype / wctype.h
blob0ecb69d6bd8b4df83085d0f7f9febf04facd1ad9
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) ((bit) < 8 ? 1UL << (bit) << 24 : 1UL << ((bit) + 8))
73 # endif
75 enum
77 _ISwupper = _ISwbit (0), /* UPPERCASE. */
78 _ISwlower = _ISwbit (1), /* lowercase. */
79 _ISwalpha = _ISwbit (2), /* Alphabetic. */
80 _ISwdigit = _ISwbit (3), /* Numeric. */
81 _ISwxdigit = _ISwbit (4), /* Hexadecimal numeric. */
82 _ISwspace = _ISwbit (5), /* Whitespace. */
83 _ISwprint = _ISwbit (6), /* Printing. */
84 _ISwgraph = _ISwbit (7), /* Graphical. */
85 _ISwblank = _ISwbit (8), /* Blank (usually SPC and TAB). */
86 _ISwcntrl = _ISwbit (9), /* Control character. */
87 _ISwpunct = _ISwbit (10), /* Punctuation. */
88 _ISwalnum = _ISwbit (11) /* Alphanumeric. */
90 # endif /* Not _ISwbit */
93 __BEGIN_DECLS
96 * Wide-character classification functions: 7.15.2.1.
99 /* Test for any wide character for which `iswalpha' or `iswdigit' is
100 true. */
101 extern int iswalnum __P ((wint_t __wc));
103 /* Test for any wide character for which `iswupper' or 'iswlower' is
104 true, or any wide character that is one of a locale-specific set of
105 wide-characters for which none of `iswcntrl', `iswdigit',
106 `iswpunct', or `iswspace' is true. */
107 extern int iswalpha __P ((wint_t __wc));
109 /* Test for any control wide character. */
110 extern int iswcntrl __P ((wint_t __wc));
112 /* Test for any wide character that corresponds to a decimal-digit
113 character. */
114 extern int iswdigit __P ((wint_t __wc));
116 /* Test for any wide character for which `iswprint' is true and
117 `iswspace' is false. */
118 extern int iswgraph __P ((wint_t __wc));
120 /* Test for any wide character that corresponds to a lowercase letter
121 or is one of a locale-specific set of wide characters for which
122 none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
123 extern int iswlower __P ((wint_t __wc));
125 /* Test for any printing wide character. */
126 extern int iswprint __P ((wint_t __wc));
128 /* Test for any printing wide character that is one of a
129 locale-specific et of wide characters for which neither `iswspace'
130 nor `iswalnum' is true. */
131 extern int iswpunct __P ((wint_t __wc));
133 /* Test for any wide character that corresponds to a locale-specific
134 set of wide characters for which none of `iswalnum', `iswgraph', or
135 `iswpunct' is true. */
136 extern int iswspace __P ((wint_t __wc));
138 /* Test for any wide character that corresponds to an uppercase letter
139 or is one of a locale-specific set of wide character for which none
140 of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
141 extern int iswupper __P ((wint_t __wc));
143 /* Test for any wide character that corresponds to a hexadecimal-digit
144 character equivalent to that performed be the functions described
145 in the previous subclause. */
146 extern int iswxdigit __P ((wint_t __wc));
148 /* Test for any wide character that corresponds to a standard blank
149 wide character or a locale-specific set of wide characters for
150 which `iswalnum' is false. */
151 # ifdef __USE_GNU
152 extern int iswblank __P ((wint_t __wc));
153 # endif
156 * Extensible wide-character classification functions: 7.15.2.2.
159 /* Construct value that describes a class of wide characters identified
160 by the string argument PROPERTY. */
161 extern wctype_t __wctype __P ((__const char *__property));
162 extern wctype_t wctype __P ((__const char *__property));
164 /* Determine whether the wide-character WC has the property described by
165 DESC. */
166 extern int __iswctype __P ((wint_t __wc, wctype_t __desc));
167 extern int iswctype __P ((wint_t __wc, wctype_t __desc));
169 #if __GNUC__ >= 2 && defined __OPTIMIZE__
170 /* The tables are always organized in a way which allows direct access
171 for single byte characters. */
172 extern unsigned int *__ctype32_b;
174 # define iswalnum(wc) \
175 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
176 ? (int) (__ctype32_b[wc] & _ISwalnum) : iswalnum (wc))
177 # define iswalpha(wc) \
178 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
179 ? (int) (__ctype32_b[wc] & _ISwalpha) : iswalpha (wc))
180 # define iswcntrl(wc) \
181 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
182 ? (int) (__ctype32_b[wc] & _ISwcntrl) : iswcntrl (wc))
183 # define iswdigit(wc) \
184 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
185 ? (int) (__ctype32_b[wc] & _ISwdigit) : iswdigit (wc))
186 # define iswlower(wc) \
187 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
188 ? (int) (__ctype32_b[wc] & _ISwlower) : iswlower (wc))
189 # define iswgraph(wc) \
190 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
191 ? (int) (__ctype32_b[wc] & _ISwgraph) : iswgraph (wc))
192 # define iswprint(wc) \
193 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
194 ? (int) (__ctype32_b[wc] & _ISwprint) : iswprint (wc))
195 # define iswpunct(wc) \
196 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
197 ? (int) (__ctype32_b[wc] & _ISwpunct) : iswpunct (wc))
198 # define iswspace(wc) \
199 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
200 ? (int) (__ctype32_b[wc] & _ISwspace) : iswspace (wc))
201 # define iswupper(wc) \
202 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
203 ? (int) (__ctype32_b[wc] & _ISwupper) : iswupper (wc))
204 # define iswxdigit(wc) \
205 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
206 ? (int) (__ctype32_b[wc] & _ISwxdigit) : iswxdigit (wc))
208 # ifdef __USE_GNU
209 # define iswblank(wc) \
210 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
211 ? (int) (__ctype32_b[wc] & _ISwblank) : iswblank (wc))
212 # endif
214 # define iswctype(wc, desc) \
215 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
216 ? (int) (__ctype32_b[wc] & desc) : iswctype (wc, desc))
218 #endif /* gcc && optimizing */
221 * Wide-character case-mapping functions: 7.15.3.1.
224 /* Scalar type that can hold values which represent locale-specific
225 character mappings. */
226 typedef __const __int32_t *wctrans_t;
228 /* Converts an uppercase letter to the corresponding lowercase letter. */
229 extern wint_t towlower __P ((wint_t __wc));
231 /* Converts an lowercase letter to the corresponding uppercase letter. */
232 extern wint_t towupper __P ((wint_t __wc));
234 /* Map the wide character WC using the mapping described by DESC. */
235 extern wint_t __towctrans __P ((wint_t __wc, wctrans_t __desc));
237 #if __GNUC__ >= 2 && defined __OPTIMIZE__
238 /* The tables are always organized in a way which allows direct access
239 for single byte characters. */
240 extern __const __int32_t *__ctype_tolower; /* Case conversions. */
241 extern __const __int32_t *__ctype_toupper; /* Case conversions. */
243 # define towlower(wc) \
244 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
245 ? (wint_t) __ctype_tolower[wc] : towlower (wc))
246 # define towuppert(wc) \
247 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
248 ? (wint_t) __ctype_toupper[wc] : towupper (wc))
250 #endif /* gcc && optimizing */
252 __END_DECLS
254 #endif /* need iswxxx. */
257 /* The remaining definitions and declarations must not appear in the
258 <wcsmbs.h> header. */
259 #ifdef _WCTYPE_H
262 * Extensible wide-character mapping functions: 7.15.3.2.
265 __BEGIN_DECLS
267 /* Construct value that describes a mapping between wide characters
268 identified by the string argument PROPERTY. */
269 extern wctrans_t wctrans __P ((__const char *__property));
271 /* Map the wide character WC using the mapping described by DESC. */
272 extern wint_t towctrans __P ((wint_t __wc, wctrans_t __desc));
274 # ifdef __USE_GNU
275 /* Declare the interface to extended locale model. */
276 # include <xlocale.h>
278 /* Test for any wide character for which `iswalpha' or `iswdigit' is
279 true. */
280 extern int __iswalnum_l __P ((wint_t __wc, __locale_t __locale));
282 /* Test for any wide character for which `iswupper' or 'iswlower' is
283 true, or any wide character that is one of a locale-specific set of
284 wide-characters for which none of `iswcntrl', `iswdigit',
285 `iswpunct', or `iswspace' is true. */
286 extern int __iswalpha_l __P ((wint_t __wc, __locale_t __locale));
288 /* Test for any control wide character. */
289 extern int __iswcntrl_l __P ((wint_t __wc, __locale_t __locale));
291 /* Test for any wide character that corresponds to a decimal-digit
292 character. */
293 extern int __iswdigit_l __P ((wint_t __wc, __locale_t __locale));
295 /* Test for any wide character for which `iswprint' is true and
296 `iswspace' is false. */
297 extern int __iswgraph_l __P ((wint_t __wc, __locale_t __locale));
299 /* Test for any wide character that corresponds to a lowercase letter
300 or is one of a locale-specific set of wide characters for which
301 none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
302 extern int __iswlower_l __P ((wint_t __wc, __locale_t __locale));
304 /* Test for any printing wide character. */
305 extern int __iswprint_l __P ((wint_t __wc, __locale_t __locale));
307 /* Test for any printing wide character that is one of a
308 locale-specific et of wide characters for which neither `iswspace'
309 nor `iswalnum' is true. */
310 extern int __iswpunct_l __P ((wint_t __wc, __locale_t __locale));
312 /* Test for any wide character that corresponds to a locale-specific
313 set of wide characters for which none of `iswalnum', `iswgraph', or
314 `iswpunct' is true. */
315 extern int __iswspace_l __P ((wint_t __wc, __locale_t __locale));
317 /* Test for any wide character that corresponds to an uppercase letter
318 or is one of a locale-specific set of wide character for which none
319 of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
320 extern int __iswupper_l __P ((wint_t __wc, __locale_t __locale));
322 /* Test for any wide character that corresponds to a hexadecimal-digit
323 character equivalent to that performed be the functions described
324 in the previous subclause. */
325 extern int __iswxdigit_l __P ((wint_t __wc, __locale_t __locale));
327 /* Test for any wide character that corresponds to a standard blank
328 wide character or a locale-specific set of wide characters for
329 which `iswalnum' is false. */
330 extern int __iswblank_l __P ((wint_t __wc, __locale_t __locale));
332 /* Construct value that describes a class of wide characters identified
333 by the string argument PROPERTY. */
334 extern wctype_t __wctype_l __P ((__const char *__property,
335 __locale_t __locale));
337 /* Determine whether the wide-character WC has the property described by
338 DESC. */
339 extern int __iswctype_l __P ((wint_t __wc, wctype_t __desc,
340 __locale_t __locale));
344 * Wide-character case-mapping functions.
347 /* Converts an uppercase letter to the corresponding lowercase letter. */
348 extern wint_t __towlower_l __P ((wint_t __wc, __locale_t __locale));
350 /* Converts an lowercase letter to the corresponding uppercase letter. */
351 extern wint_t __towupper_l __P ((wint_t __wc, __locale_t __locale));
353 /* Map the wide character WC using the mapping described by DESC. */
354 extern wint_t __towctrans_l __P ((wint_t __wc, wctrans_t __desc,
355 __locale_t __locale));
357 # endif /* Use GNU. */
359 __END_DECLS
361 #endif /* __WCTYPE_H defined. */
363 #endif /* wctype.h */