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>
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
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) : (int) (1UL << ((bit) + 8)))
78 _ISwupper
= _ISwbit (0), /* UPPERCASE. */
79 _ISwlower
= _ISwbit (1), /* lowercase. */
80 _ISwalpha
= _ISwbit (2), /* Alphabetic. */
81 _ISwdigit
= _ISwbit (3), /* Numeric. */
82 _ISwxdigit
= _ISwbit (4), /* Hexadecimal numeric. */
83 _ISwspace
= _ISwbit (5), /* Whitespace. */
84 _ISwprint
= _ISwbit (6), /* Printing. */
85 _ISwgraph
= _ISwbit (7), /* Graphical. */
86 _ISwblank
= _ISwbit (8), /* Blank (usually SPC and TAB). */
87 _ISwcntrl
= _ISwbit (9), /* Control character. */
88 _ISwpunct
= _ISwbit (10), /* Punctuation. */
89 _ISwalnum
= _ISwbit (11) /* Alphanumeric. */
91 # endif /* Not _ISwbit */
97 * Wide-character classification functions: 7.15.2.1.
100 /* Test for any wide character for which `iswalpha' or `iswdigit' is
102 extern int iswalnum
__P ((wint_t __wc
));
104 /* Test for any wide character for which `iswupper' or 'iswlower' is
105 true, or any wide character that is one of a locale-specific set of
106 wide-characters for which none of `iswcntrl', `iswdigit',
107 `iswpunct', or `iswspace' is true. */
108 extern int iswalpha
__P ((wint_t __wc
));
110 /* Test for any control wide character. */
111 extern int iswcntrl
__P ((wint_t __wc
));
113 /* Test for any wide character that corresponds to a decimal-digit
115 extern int iswdigit
__P ((wint_t __wc
));
117 /* Test for any wide character for which `iswprint' is true and
118 `iswspace' is false. */
119 extern int iswgraph
__P ((wint_t __wc
));
121 /* Test for any wide character that corresponds to a lowercase letter
122 or is one of a locale-specific set of wide characters for which
123 none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
124 extern int iswlower
__P ((wint_t __wc
));
126 /* Test for any printing wide character. */
127 extern int iswprint
__P ((wint_t __wc
));
129 /* Test for any printing wide character that is one of a
130 locale-specific et of wide characters for which neither `iswspace'
131 nor `iswalnum' is true. */
132 extern int iswpunct
__P ((wint_t __wc
));
134 /* Test for any wide character that corresponds to a locale-specific
135 set of wide characters for which none of `iswalnum', `iswgraph', or
136 `iswpunct' is true. */
137 extern int iswspace
__P ((wint_t __wc
));
139 /* Test for any wide character that corresponds to an uppercase letter
140 or is one of a locale-specific set of wide character for which none
141 of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
142 extern int iswupper
__P ((wint_t __wc
));
144 /* Test for any wide character that corresponds to a hexadecimal-digit
145 character equivalent to that performed be the functions described
146 in the previous subclause. */
147 extern int iswxdigit
__P ((wint_t __wc
));
149 /* Test for any wide character that corresponds to a standard blank
150 wide character or a locale-specific set of wide characters for
151 which `iswalnum' is false. */
153 extern int iswblank
__P ((wint_t __wc
));
157 * Extensible wide-character classification functions: 7.15.2.2.
160 /* Construct value that describes a class of wide characters identified
161 by the string argument PROPERTY. */
162 extern wctype_t __wctype
__P ((__const
char *__property
));
163 extern wctype_t wctype
__P ((__const
char *__property
));
165 /* Determine whether the wide-character WC has the property described by
167 extern int __iswctype
__P ((wint_t __wc
, wctype_t __desc
));
168 extern int iswctype
__P ((wint_t __wc
, wctype_t __desc
));
170 #if __GNUC__ >= 2 && defined __OPTIMIZE__
171 /* The tables are always organized in a way which allows direct access
172 for single byte characters. */
173 extern unsigned int *__ctype32_b
;
175 # define iswalnum(wc) \
176 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
177 ? (int) (__ctype32_b[wc] & _ISwalnum) : iswalnum (wc))
178 # define iswalpha(wc) \
179 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
180 ? (int) (__ctype32_b[wc] & _ISwalpha) : iswalpha (wc))
181 # define iswcntrl(wc) \
182 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
183 ? (int) (__ctype32_b[wc] & _ISwcntrl) : iswcntrl (wc))
184 # define iswdigit(wc) \
185 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
186 ? (int) (__ctype32_b[wc] & _ISwdigit) : iswdigit (wc))
187 # define iswlower(wc) \
188 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
189 ? (int) (__ctype32_b[wc] & _ISwlower) : iswlower (wc))
190 # define iswgraph(wc) \
191 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
192 ? (int) (__ctype32_b[wc] & _ISwgraph) : iswgraph (wc))
193 # define iswprint(wc) \
194 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
195 ? (int) (__ctype32_b[wc] & _ISwprint) : iswprint (wc))
196 # define iswpunct(wc) \
197 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
198 ? (int) (__ctype32_b[wc] & _ISwpunct) : iswpunct (wc))
199 # define iswspace(wc) \
200 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
201 ? (int) (__ctype32_b[wc] & _ISwspace) : iswspace (wc))
202 # define iswupper(wc) \
203 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
204 ? (int) (__ctype32_b[wc] & _ISwupper) : iswupper (wc))
205 # define iswxdigit(wc) \
206 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
207 ? (int) (__ctype32_b[wc] & _ISwxdigit) : iswxdigit (wc))
210 # define iswblank(wc) \
211 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
212 ? (int) (__ctype32_b[wc] & _ISwblank) : iswblank (wc))
215 # define iswctype(wc, desc) \
216 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
217 ? (int) (__ctype32_b[wc] & desc) : iswctype (wc, desc))
219 #endif /* gcc && optimizing */
222 * Wide-character case-mapping functions: 7.15.3.1.
225 /* Scalar type that can hold values which represent locale-specific
226 character mappings. */
227 typedef __const __int32_t
*wctrans_t;
229 /* Converts an uppercase letter to the corresponding lowercase letter. */
230 extern wint_t towlower
__P ((wint_t __wc
));
232 /* Converts an lowercase letter to the corresponding uppercase letter. */
233 extern wint_t towupper
__P ((wint_t __wc
));
235 /* Map the wide character WC using the mapping described by DESC. */
236 extern wint_t __towctrans
__P ((wint_t __wc
, wctrans_t __desc
));
238 #if __GNUC__ >= 2 && defined __OPTIMIZE__
239 /* The tables are always organized in a way which allows direct access
240 for single byte characters. */
241 extern __const __int32_t
*__ctype_tolower
; /* Case conversions. */
242 extern __const __int32_t
*__ctype_toupper
; /* Case conversions. */
244 # define towlower(wc) \
245 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
246 ? (wint_t) __ctype_tolower[wc] : towlower (wc))
247 # define towuppert(wc) \
248 (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff' \
249 ? (wint_t) __ctype_toupper[wc] : towupper (wc))
251 #endif /* gcc && optimizing */
255 #endif /* need iswxxx. */
258 /* The remaining definitions and declarations must not appear in the
259 <wcsmbs.h> header. */
263 * Extensible wide-character mapping functions: 7.15.3.2.
268 /* Construct value that describes a mapping between wide characters
269 identified by the string argument PROPERTY. */
270 extern wctrans_t wctrans
__P ((__const
char *__property
));
272 /* Map the wide character WC using the mapping described by DESC. */
273 extern wint_t towctrans
__P ((wint_t __wc
, wctrans_t __desc
));
276 /* Declare the interface to extended locale model. */
277 # include <xlocale.h>
279 /* Test for any wide character for which `iswalpha' or `iswdigit' is
281 extern int __iswalnum_l
__P ((wint_t __wc
, __locale_t __locale
));
283 /* Test for any wide character for which `iswupper' or 'iswlower' is
284 true, or any wide character that is one of a locale-specific set of
285 wide-characters for which none of `iswcntrl', `iswdigit',
286 `iswpunct', or `iswspace' is true. */
287 extern int __iswalpha_l
__P ((wint_t __wc
, __locale_t __locale
));
289 /* Test for any control wide character. */
290 extern int __iswcntrl_l
__P ((wint_t __wc
, __locale_t __locale
));
292 /* Test for any wide character that corresponds to a decimal-digit
294 extern int __iswdigit_l
__P ((wint_t __wc
, __locale_t __locale
));
296 /* Test for any wide character for which `iswprint' is true and
297 `iswspace' is false. */
298 extern int __iswgraph_l
__P ((wint_t __wc
, __locale_t __locale
));
300 /* Test for any wide character that corresponds to a lowercase letter
301 or is one of a locale-specific set of wide characters for which
302 none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
303 extern int __iswlower_l
__P ((wint_t __wc
, __locale_t __locale
));
305 /* Test for any printing wide character. */
306 extern int __iswprint_l
__P ((wint_t __wc
, __locale_t __locale
));
308 /* Test for any printing wide character that is one of a
309 locale-specific et of wide characters for which neither `iswspace'
310 nor `iswalnum' is true. */
311 extern int __iswpunct_l
__P ((wint_t __wc
, __locale_t __locale
));
313 /* Test for any wide character that corresponds to a locale-specific
314 set of wide characters for which none of `iswalnum', `iswgraph', or
315 `iswpunct' is true. */
316 extern int __iswspace_l
__P ((wint_t __wc
, __locale_t __locale
));
318 /* Test for any wide character that corresponds to an uppercase letter
319 or is one of a locale-specific set of wide character for which none
320 of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
321 extern int __iswupper_l
__P ((wint_t __wc
, __locale_t __locale
));
323 /* Test for any wide character that corresponds to a hexadecimal-digit
324 character equivalent to that performed be the functions described
325 in the previous subclause. */
326 extern int __iswxdigit_l
__P ((wint_t __wc
, __locale_t __locale
));
328 /* Test for any wide character that corresponds to a standard blank
329 wide character or a locale-specific set of wide characters for
330 which `iswalnum' is false. */
331 extern int __iswblank_l
__P ((wint_t __wc
, __locale_t __locale
));
333 /* Construct value that describes a class of wide characters identified
334 by the string argument PROPERTY. */
335 extern wctype_t __wctype_l
__P ((__const
char *__property
,
336 __locale_t __locale
));
338 /* Determine whether the wide-character WC has the property described by
340 extern int __iswctype_l
__P ((wint_t __wc
, wctype_t __desc
,
341 __locale_t __locale
));
345 * Wide-character case-mapping functions.
348 /* Converts an uppercase letter to the corresponding lowercase letter. */
349 extern wint_t __towlower_l
__P ((wint_t __wc
, __locale_t __locale
));
351 /* Converts an lowercase letter to the corresponding uppercase letter. */
352 extern wint_t __towupper_l
__P ((wint_t __wc
, __locale_t __locale
));
354 /* Map the wide character WC using the mapping described by DESC. */
355 extern wint_t __towctrans_l
__P ((wint_t __wc
, wctrans_t __desc
,
356 __locale_t __locale
));
358 # endif /* Use GNU. */
362 #endif /* __WCTYPE_H defined. */
364 #endif /* wctype.h */