* ctype/ctype.h (isascii_l, toascii_l): Define to __*_l counterparts.
[platform/upstream/glibc.git] / wctype / wctype.h
1 /* Copyright (C) 1996,97,98,99,2000,01,02 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
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.
8
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.
13
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
17    02111-1307 USA.  */
18
19 /*
20  *      ISO C99 Standard: 7.25
21  *      Wide character classification and mapping utilities  <wctype.h>
22  */
23
24 #ifndef _WCTYPE_H
25
26 #include <features.h>
27 #include <bits/types.h>
28
29 #ifndef __need_iswxxx
30 # define _WCTYPE_H      1
31
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
44
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
52
53
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
58
59 /* Scalar type that can hold values which represent locale-specific
60    character classifications.  */
61 typedef unsigned long int wctype_t;
62
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.  */
67
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
78
79 enum
80 {
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.  */
93
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.  */
106 };
107 # endif /* Not _ISwbit  */
108
109
110 __BEGIN_DECLS
111
112 /*
113  * Wide-character classification functions: 7.15.2.1.
114  */
115
116 /* Test for any wide character for which `iswalpha' or `iswdigit' is
117    true.  */
118 extern int iswalnum (wint_t __wc) __THROW;
119
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;
125
126 /* Test for any control wide character.  */
127 extern int iswcntrl (wint_t __wc) __THROW;
128
129 /* Test for any wide character that corresponds to a decimal-digit
130    character.  */
131 extern int iswdigit (wint_t __wc) __THROW;
132
133 /* Test for any wide character for which `iswprint' is true and
134    `iswspace' is false.  */
135 extern int iswgraph (wint_t __wc) __THROW;
136
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;
141
142 /* Test for any printing wide character.  */
143 extern int iswprint (wint_t __wc) __THROW;
144
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;
149
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;
154
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;
159
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;
164
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
171
172 /*
173  * Extensible wide-character classification functions: 7.15.2.2.
174  */
175
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;
179
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;
183
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;
188
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)))
233
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
240
241 #endif  /* gcc && optimizing */
242
243 /*
244  * Wide-character case-mapping functions: 7.15.3.1.
245  */
246
247 /* Scalar type that can hold values which represent locale-specific
248    character mappings.  */
249 typedef __const __int32_t *wctrans_t;
250
251 /* Converts an uppercase letter to the corresponding lowercase letter.  */
252 extern wint_t towlower (wint_t __wc) __THROW;
253
254 /* Converts an lowercase letter to the corresponding uppercase letter.  */
255 extern wint_t towupper (wint_t __wc) __THROW;
256
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;
262
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)))
267
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)))
272
273 #endif  /* gcc && optimizing */
274
275 __END_DECLS
276
277 #endif  /* need iswxxx.  */
278
279
280 /* The remaining definitions and declarations must not appear in the
281    <wcsmbs.h> header.  */
282 #ifdef _WCTYPE_H
283
284 /*
285  * Extensible wide-character mapping functions: 7.15.3.2.
286  */
287
288 __BEGIN_DECLS
289
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;
293
294 /* Map the wide character WC using the mapping described by DESC.  */
295 extern wint_t towctrans (wint_t __wc, wctrans_t __desc) __THROW;
296
297 # ifdef __USE_GNU
298 /* Declare the interface to extended locale model.  */
299 #  include <xlocale.h>
300
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;
304
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;
310
311 /* Test for any control wide character.  */
312 extern int iswcntrl_l (wint_t __wc, __locale_t __locale) __THROW;
313
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;
317
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;
321
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;
326
327 /* Test for any printing wide character.  */
328 extern int iswprint_l (wint_t __wc, __locale_t __locale) __THROW;
329
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;
334
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;
339
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;
344
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;
349
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;
354
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;
359
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;
364
365
366 /*
367  * Wide-character case-mapping functions.
368  */
369
370 /* Converts an uppercase letter to the corresponding lowercase letter.  */
371 extern wint_t towlower_l (wint_t __wc, __locale_t __locale) __THROW;
372
373 /* Converts an lowercase letter to the corresponding uppercase letter.  */
374 extern wint_t towupper_l (wint_t __wc, __locale_t __locale) __THROW;
375
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;
380
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;
384
385 # endif /* Use GNU.  */
386
387 __END_DECLS
388
389 #endif  /* __WCTYPE_H defined.  */
390
391 #endif /* wctype.h  */