Update.
[platform/upstream/glibc.git] / wctype / wctype.h
1 /* Copyright (C) 1996, 1997, 1998, 1999 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 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.
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    Library General Public License for more details.
13
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.  */
18
19 /*
20  *      ISO C Standard, Amendment 1, 7.15:
21  *      Wide-character classification and mapping utilities  <wctype.h>
22  */
23
24 #ifndef _WCTYPE_H
25
26 #ifndef __need_iswxxx
27 # define _WCTYPE_H      1
28
29 # include <features.h>
30 # include <bits/types.h>
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) : (int) (1UL << ((bit) + 8)))
74 #  endif
75
76 enum
77 {
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.  */
90 };
91 # endif /* Not _ISwbit  */
92
93
94 __BEGIN_DECLS
95
96 /*
97  * Wide-character classification functions: 7.15.2.1.
98  */
99
100 /* Test for any wide character for which `iswalpha' or `iswdigit' is
101    true.  */
102 extern int iswalnum __P ((wint_t __wc));
103
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));
109
110 /* Test for any control wide character.  */
111 extern int iswcntrl __P ((wint_t __wc));
112
113 /* Test for any wide character that corresponds to a decimal-digit
114    character.  */
115 extern int iswdigit __P ((wint_t __wc));
116
117 /* Test for any wide character for which `iswprint' is true and
118    `iswspace' is false.  */
119 extern int iswgraph __P ((wint_t __wc));
120
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));
125
126 /* Test for any printing wide character.  */
127 extern int iswprint __P ((wint_t __wc));
128
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));
133
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));
138
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));
143
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));
148
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.  */
152 # ifdef __USE_GNU
153 extern int iswblank __P ((wint_t __wc));
154 # endif
155
156 /*
157  * Extensible wide-character classification functions: 7.15.2.2.
158  */
159
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));
164
165 /* Determine whether the wide-character WC has the property described by
166    DESC.  */
167 extern int __iswctype __P ((wint_t __wc, wctype_t __desc));
168 extern int iswctype __P ((wint_t __wc, wctype_t __desc));
169
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;
174
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))
208
209 # ifdef __USE_GNU
210 #  define iswblank(wc) \
211   (__builtin_constant_p (wc) && (wc) >= L'\0' && (wc) <= L'\xff'              \
212    ? (int) (__ctype32_b[wc] & _ISwblank) : iswblank (wc))
213 # endif
214
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))
218
219 #endif  /* gcc && optimizing */
220
221 /*
222  * Wide-character case-mapping functions: 7.15.3.1.
223  */
224
225 /* Scalar type that can hold values which represent locale-specific
226    character mappings.  */
227 typedef __const __int32_t *wctrans_t;
228
229 /* Converts an uppercase letter to the corresponding lowercase letter.  */
230 extern wint_t towlower __P ((wint_t __wc));
231
232 /* Converts an lowercase letter to the corresponding uppercase letter.  */
233 extern wint_t towupper __P ((wint_t __wc));
234
235 /* Map the wide character WC using the mapping described by DESC.  */
236 extern wint_t __towctrans __P ((wint_t __wc, wctrans_t __desc));
237
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.  */
243
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))
250
251 #endif  /* gcc && optimizing */
252
253 __END_DECLS
254
255 #endif  /* need iswxxx.  */
256
257
258 /* The remaining definitions and declarations must not appear in the
259    <wcsmbs.h> header.  */
260 #ifdef _WCTYPE_H
261
262 /*
263  * Extensible wide-character mapping functions: 7.15.3.2.
264  */
265
266 __BEGIN_DECLS
267
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));
271
272 /* Map the wide character WC using the mapping described by DESC.  */
273 extern wint_t towctrans __P ((wint_t __wc, wctrans_t __desc));
274
275 # ifdef __USE_GNU
276 /* Declare the interface to extended locale model.  */
277 #  include <xlocale.h>
278
279 /* Test for any wide character for which `iswalpha' or `iswdigit' is
280    true.  */
281 extern int __iswalnum_l __P ((wint_t __wc, __locale_t __locale));
282
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));
288
289 /* Test for any control wide character.  */
290 extern int __iswcntrl_l __P ((wint_t __wc, __locale_t __locale));
291
292 /* Test for any wide character that corresponds to a decimal-digit
293    character.  */
294 extern int __iswdigit_l __P ((wint_t __wc, __locale_t __locale));
295
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));
299
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));
304
305 /* Test for any printing wide character.  */
306 extern int __iswprint_l __P ((wint_t __wc, __locale_t __locale));
307
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));
312
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));
317
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));
322
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));
327
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));
332
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));
337
338 /* Determine whether the wide-character WC has the property described by
339    DESC.  */
340 extern int __iswctype_l __P ((wint_t __wc, wctype_t __desc,
341                               __locale_t __locale));
342
343
344 /*
345  * Wide-character case-mapping functions.
346  */
347
348 /* Converts an uppercase letter to the corresponding lowercase letter.  */
349 extern wint_t __towlower_l __P ((wint_t __wc, __locale_t __locale));
350
351 /* Converts an lowercase letter to the corresponding uppercase letter.  */
352 extern wint_t __towupper_l __P ((wint_t __wc, __locale_t __locale));
353
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));
357
358 # endif /* Use GNU.  */
359
360 __END_DECLS
361
362 #endif  /* __WCTYPE_H defined.  */
363
364 #endif /* wctype.h  */