Update.
[platform/upstream/glibc.git] / wctype / wctype.h
1 /* Copyright (C) 1996, 1997 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 #define _WCTYPE_H       1
26
27 #include <features.h>
28 #include <bits/types.h>
29
30 __BEGIN_DECLS
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 /* Scalar type that can hold values which represent locale-specific
46    character mappings.  */
47 typedef __const unsigned int *wctrans_t;
48
49 /* Scalar type that can hold values which represent locale-specific
50    character classifications.  */
51 typedef unsigned long int wctype_t;
52
53 /* Constant expression of type `wint_t' whose value does not correspond
54    to any member of the extended character set.  */
55 #ifndef WEOF
56 # define WEOF (0xffffffffu)
57 #endif
58
59 #ifndef _ISbit
60 /* The characteristics are stored always in network byte order (big
61    endian).  We define the bit value interpretations here dependent on the
62    machine's byte order.  */
63
64 # include <endian.h>
65 # if __BYTE_ORDER == __BIG_ENDIAN
66 #  define _ISbit(bit)   (1 << bit)
67 # else /* __BYTE_ORDER == __LITTLE_ENDIAN */
68 #  define _ISbit(bit)   (bit < 8 ? ((1 << bit) << 8) : ((1 << bit) >> 8))
69 # endif
70
71 enum
72 {
73   _ISupper = _ISbit (0),        /* UPPERCASE.  */
74   _ISlower = _ISbit (1),        /* lowercase.  */
75   _ISalpha = _ISbit (2),        /* Alphabetic.  */
76   _ISdigit = _ISbit (3),        /* Numeric.  */
77   _ISxdigit = _ISbit (4),       /* Hexadecimal numeric.  */
78   _ISspace = _ISbit (5),        /* Whitespace.  */
79   _ISprint = _ISbit (6),        /* Printing.  */
80   _ISgraph = _ISbit (7),        /* Graphical.  */
81   _ISblank = _ISbit (8),        /* Blank (usually SPC and TAB).  */
82   _IScntrl = _ISbit (9),        /* Control character.  */
83   _ISpunct = _ISbit (10),       /* Punctuation.  */
84   _ISalnum = _ISbit (11)        /* Alphanumeric.  */
85 };
86 #endif /* Not _ISbit  */
87
88
89 /*
90  * Wide-character classification functions: 7.15.2.1.
91  */
92
93 /* Test for any wide character for which `iswalpha' or `iswdigit' is
94    true.  */
95 extern int iswalnum __P ((wint_t __wc));
96
97 /* Test for any wide character for which `iswupper' or 'iswlower' is
98    true, or any wide character that is one of a locale-specific set of
99    wide-characters for which none of `iswcntrl', `iswdigit',
100    `iswpunct', or `iswspace' is true.  */
101 extern int iswalpha __P ((wint_t __wc));
102
103 /* Test for any control wide character.  */
104 extern int iswcntrl __P ((wint_t __wc));
105
106 /* Test for any wide character that corresponds to a decimal-digit
107    character.  */
108 extern int iswdigit __P ((wint_t __wc));
109
110 /* Test for any wide character for which `iswprint' is true and
111    `iswspace' is false.  */
112 extern int iswgraph __P ((wint_t __wc));
113
114 /* Test for any wide character that corresponds to a lowercase letter
115    or is one of a locale-specific set of wide characters for which
116    none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true.  */
117 extern int iswlower __P ((wint_t __wc));
118
119 /* Test for any printing wide character.  */
120 extern int iswprint __P ((wint_t __wc));
121
122 /* Test for any printing wide character that is one of a
123    locale-specific et of wide characters for which neither `iswspace'
124    nor `iswalnum' is true.  */
125 extern int iswpunct __P ((wint_t __wc));
126
127 /* Test for any wide character that corresponds to a locale-specific
128    set of wide characters for which none of `iswalnum', `iswgraph', or
129    `iswpunct' is true.  */
130 extern int iswspace __P ((wint_t __wc));
131
132 /* Test for any wide character that corresponds to an uppercase letter
133    or is one of a locale-specific set of wide character for which none
134    of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true.  */
135 extern int iswupper __P ((wint_t __wc));
136
137 /* Test for any wide character that corresponds to a hexadecimal-digit
138    character equivalent to that performed be the functions described
139    in the previous subclause.  */
140 extern int iswxdigit __P ((wint_t __wc));
141
142 /*
143  * Extensible wide-character classification functions: 7.15.2.2.
144  */
145
146 /* Construct value that describes a class of wide characters identified
147    by the string argument PROPERTY.  */
148 extern wctype_t wctype __P ((__const char *__property));
149
150 /* Determine whether the wide-character WC has the property described by
151    DESC.  */
152 extern int __iswctype __P ((wint_t __wc, wctype_t __desc));
153 extern int iswctype __P ((wint_t __wc, wctype_t __desc));
154
155
156 /*
157  * Wide-character case-mapping functions: 7.15.3.1.
158  */
159
160 /* Converts an uppercase letter to the corresponding lowercase letter.  */
161 extern wint_t towlower __P ((wint_t __wc));
162
163 /* Converts an lowercase letter to the corresponding uppercase letter.  */
164 extern wint_t towupper __P ((wint_t __wc));
165
166 /*
167  * Extensible wide-character mapping functions: 7.15.3.2.
168  */
169
170 /* Construct value that describes a mapping between wide characters
171    identified by the string argument PROPERTY.  */
172 extern wctrans_t wctrans __P ((__const char *__property));
173
174 /* Map the wide character WC using the mapping described by DESC.  */
175 extern wint_t towctrans __P ((wint_t __wc, wctrans_t __desc));
176
177
178
179 #ifndef __NO_WCTYPE
180 # define iswalnum(wc)   __iswctype ((wc), _ISalnum)
181 # define iswalpha(wc)   __iswctype ((wc), _ISalpha)
182 # define iswcntrl(wc)   __iswctype ((wc), _IScntrl)
183 # define iswdigit(wc)   __iswctype ((wc), _ISdigit)
184 # define iswlower(wc)   __iswctype ((wc), _ISlower)
185 # define iswgraph(wc)   __iswctype ((wc), _ISgraph)
186 # define iswprint(wc)   __iswctype ((wc), _ISprint)
187 # define iswpunct(wc)   __iswctype ((wc), _ISpunct)
188 # define iswspace(wc)   __iswctype ((wc), _ISspace)
189 # define iswupper(wc)   __iswctype ((wc), _ISupper)
190 # define iswxdigit(wc)  __iswctype ((wc), _ISxdigit)
191
192 # ifdef __USE_GNU
193 #  define iswblank(wc)  __iswctype ((wc), _ISblank)
194 # endif
195
196 /* Pointer to conversion tables.  */
197 extern __const __int32_t *__ctype_tolower; /* Case conversions.  */
198 extern __const __int32_t *__ctype_toupper; /* Case conversions.  */
199
200 # define towlower(wc)   towctrans ((wc), __ctype_tolower)
201 # define towupper(wc)   towctrans ((wc), __ctype_toupper)
202
203 #endif /* Not __NO_WCTYPE.  */
204
205 #ifdef __USE_GNU
206 /* Declare the interface to extended locale model.  */
207 # include <xlocale.h>
208
209 /* Test for any wide character for which `iswalpha' or `iswdigit' is
210    true.  */
211 extern int __iswalnum_l __P ((wint_t __wc, __locale_t __locale));
212
213 /* Test for any wide character for which `iswupper' or 'iswlower' is
214    true, or any wide character that is one of a locale-specific set of
215    wide-characters for which none of `iswcntrl', `iswdigit',
216    `iswpunct', or `iswspace' is true.  */
217 extern int __iswalpha_l __P ((wint_t __wc, __locale_t __locale));
218
219 /* Test for any control wide character.  */
220 extern int __iswcntrl_l __P ((wint_t __wc, __locale_t __locale));
221
222 /* Test for any wide character that corresponds to a decimal-digit
223    character.  */
224 extern int __iswdigit_l __P ((wint_t __wc, __locale_t __locale));
225
226 /* Test for any wide character for which `iswprint' is true and
227    `iswspace' is false.  */
228 extern int __iswgraph_l __P ((wint_t __wc, __locale_t __locale));
229
230 /* Test for any wide character that corresponds to a lowercase letter
231    or is one of a locale-specific set of wide characters for which
232    none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true.  */
233 extern int __iswlower_l __P ((wint_t __wc, __locale_t __locale));
234
235 /* Test for any printing wide character.  */
236 extern int __iswprint_l __P ((wint_t __wc, __locale_t __locale));
237
238 /* Test for any printing wide character that is one of a
239    locale-specific et of wide characters for which neither `iswspace'
240    nor `iswalnum' is true.  */
241 extern int __iswpunct_l __P ((wint_t __wc, __locale_t __locale));
242
243 /* Test for any wide character that corresponds to a locale-specific
244    set of wide characters for which none of `iswalnum', `iswgraph', or
245    `iswpunct' is true.  */
246 extern int __iswspace_l __P ((wint_t __wc, __locale_t __locale));
247
248 /* Test for any wide character that corresponds to an uppercase letter
249    or is one of a locale-specific set of wide character for which none
250    of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true.  */
251 extern int __iswupper_l __P ((wint_t __wc, __locale_t __locale));
252
253 /* Test for any wide character that corresponds to a hexadecimal-digit
254    character equivalent to that performed be the functions described
255    in the previous subclause.  */
256 extern int __iswxdigit_l __P ((wint_t __wc, __locale_t __locale));
257
258
259 /* Construct value that describes a class of wide characters identified
260    by the string argument PROPERTY.  */
261 extern wctype_t __wctype_l __P ((__const char *__property,
262                                  __locale_t __locale));
263
264 /* Determine whether the wide-character WC has the property described by
265    DESC.  */
266 extern int __iswctype_l __P ((wint_t __wc, wctype_t __desc,
267                               __locale_t __locale));
268
269
270 /*
271  * Wide-character case-mapping functions.
272  */
273
274 /* Converts an uppercase letter to the corresponding lowercase letter.  */
275 extern wint_t __towlower_l __P ((wint_t __wc, __locale_t __locale));
276
277 /* Converts an lowercase letter to the corresponding uppercase letter.  */
278 extern wint_t __towupper_l __P ((wint_t __wc, __locale_t __locale));
279
280 /* Map the wide character WC using the mapping described by DESC.  */
281 extern wint_t __towctrans_l __P ((wint_t __wc, wctrans_t __desc,
282                                   __locale_t __locale));
283
284
285 # ifndef __NO_WCTYPE
286 #  define __iswalnum_l(wc, loc)  __iswctype_l ((wc), _ISalnum, (loc))
287 #  define __iswalpha_l(wc, loc)  __iswctype_l ((wc), _ISalpha, (loc))
288 #  define __iswcntrl_l(wc, loc)  __iswctype_l ((wc), _IScntrl, (loc))
289 #  define __iswdigit_l(wc, loc)  __iswctype_l ((wc), _ISdigit, (loc))
290 #  define __iswlower_l(wc, loc)  __iswctype_l ((wc), _ISlower, (loc))
291 #  define __iswgraph_l(wc, loc)  __iswctype_l ((wc), _ISgraph, (loc))
292 #  define __iswprint_l(wc, loc)  __iswctype_l ((wc), _ISprint, (loc))
293 #  define __iswpunct_l(wc, loc)  __iswctype_l ((wc), _ISpunct, (loc))
294 #  define __iswspace_l(wc, loc)  __iswctype_l ((wc), _ISspace, (loc))
295 #  define __iswupper_l(wc, loc)  __iswctype_l ((wc), _ISupper, (loc))
296 #  define __iswxdigit_l(wc, loc) __iswctype_l ((wc), _ISxdigit, (loc))
297
298 #  define __iswblank_l(wc, loc)  __iswctype_l ((wc), _ISblank, (loc))
299
300 #  define __towlower_l(wc, loc)  __towctrans_l ((wc), (loc)->__ctype_tolower, \
301                                                 (loc))
302 #  define __towupper_l(wc, loc)  __towctrans_l ((wc), (loc)->__ctype_toupper, \
303                                                 (loc))
304
305 # endif /* Not __NO_WCTYPE.  */
306
307 #endif /* Use GNU.  */
308
309 __END_DECLS
310
311 #endif /* wctype.h  */