1 /* Copyright (C) 1996,97,98,99,2000,01,02 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 Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 * ISO C99 Standard: 7.25
21 * Wide character classification and mapping utilities <wctype.h>
27 #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
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. */
42 typedef unsigned int wint_t;
45 /* Constant expression of type `wint_t' whose value does not correspond
46 to any member of the extended character set. */
48 # define WEOF (0xffffffffu)
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;
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. */
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))))
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 */
113 * Wide-character classification functions: 7.15.2.1.
116 /* Test for any wide character for which `iswalpha' or `iswdigit' is
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
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. */
169 extern int iswblank (wint_t __wc) __THROW;
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
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) \
191 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
192 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwalnum) : iswalnum (wc)))
193 # define iswalpha(wc) \
195 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
196 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwalpha) : iswalpha (wc)))
197 # define iswcntrl(wc) \
199 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
200 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwcntrl) : iswcntrl (wc)))
201 # define iswdigit(wc) \
203 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
204 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwdigit) : iswdigit (wc)))
205 # define iswlower(wc) \
207 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
208 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwlower) : iswlower (wc)))
209 # define iswgraph(wc) \
211 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
212 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwgraph) : iswgraph (wc)))
213 # define iswprint(wc) \
215 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
216 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwprint) : iswprint (wc)))
217 # define iswpunct(wc) \
219 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
220 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwpunct) : iswpunct (wc)))
221 # define iswspace(wc) \
223 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
224 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwspace) : iswspace (wc)))
225 # define iswupper(wc) \
227 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
228 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwupper) : iswupper (wc)))
229 # define iswxdigit(wc) \
231 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
232 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwxdigit) : iswxdigit (wc)))
235 # define iswblank(wc) \
237 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
238 ? (int) (__ctype32_b[(wint_t) (wc)] & _ISwblank) : iswblank (wc)))
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) \
265 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
266 ? (wint_t) __ctype32_tolower[(wint_t) (wc)] : towlower (wc)))
268 # define towupper(wc) \
270 (__builtin_constant_p (wc) && (wint_t) (wc) <= L'\xff' \
271 ? (wint_t) __ctype32_toupper[(wint_t) (wc)] : towupper (wc)))
273 #endif /* gcc && optimizing */
277 #endif /* need iswxxx. */
280 /* The remaining definitions and declarations must not appear in the
281 <wcsmbs.h> header. */
285 * Extensible wide-character mapping functions: 7.15.3.2.
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;
298 /* Declare the interface to extended locale model. */
299 # include <xlocale.h>
301 /* Test for any wide character for which `iswalpha' or `iswdigit' is
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
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)
360 /* Determine whether the wide-character WC has the property described by
362 extern int iswctype_l (wint_t __wc, wctype_t __desc, __locale_t __locale)
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)
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. */
389 #endif /* __WCTYPE_H defined. */
391 #endif /* wctype.h */