1 /* Copyright (C) 1996, 1997 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>
28 #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. */
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 /* Scalar type that can hold values which represent locale-specific
46 character mappings. */
47 typedef __const
unsigned int *wctrans_t;
49 /* Scalar type that can hold values which represent locale-specific
50 character classifications. */
51 typedef unsigned long int wctype_t;
53 /* Constant expression of type `wint_t' whose value does not correspond
54 to any member of the extended character set. */
56 # define WEOF (0xffffffffu)
60 /* These are all the characteristics of characters.
61 If there get to be more than 16 distinct characteristics,
62 many things must be changed that use `unsigned short int's.
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 _ISbit(bit) (1 << bit)
71 # else /* __BYTE_ORDER == __LITTLE_ENDIAN */
72 # define _ISbit(bit) (bit < 8 ? ((1 << bit) << 8) : ((1 << bit) >> 8))
77 _ISupper
= _ISbit (0), /* UPPERCASE. */
78 _ISlower
= _ISbit (1), /* lowercase. */
79 _ISalpha
= _ISbit (2), /* Alphabetic. */
80 _ISdigit
= _ISbit (3), /* Numeric. */
81 _ISxdigit
= _ISbit (4), /* Hexadecimal numeric. */
82 _ISspace
= _ISbit (5), /* Whitespace. */
83 _ISprint
= _ISbit (6), /* Printing. */
84 _ISgraph
= _ISbit (7), /* Graphical. */
85 _ISblank
= _ISbit (8), /* Blank (usually SPC and TAB). */
86 _IScntrl
= _ISbit (9), /* Control character. */
87 _ISpunct
= _ISbit (10), /* Punctuation. */
88 _ISalnum
= _ISbit (11) /* Alphanumeric. */
90 #endif /* Not _ISbit */
94 * Wide-character classification functions: 7.15.2.1.
97 /* Test for any wide character for which `iswalpha' or `iswdigit' is
99 extern int iswalnum
__P ((wint_t __wc
));
101 /* Test for any wide character for which `iswupper' or 'iswlower' is
102 true, or any wide character that is one of a locale-specific set of
103 wide-characters for which none of `iswcntrl', `iswdigit',
104 `iswpunct', or `iswspace' is true. */
105 extern int iswalpha
__P ((wint_t __wc
));
107 /* Test for any control wide character. */
108 extern int iswcntrl
__P ((wint_t __wc
));
110 /* Test for any wide character that corresponds to a decimal-digit
112 extern int iswdigit
__P ((wint_t __wc
));
114 /* Test for any wide character for which `iswprint' is true and
115 `iswspace' is false. */
116 extern int iswgraph
__P ((wint_t __wc
));
118 /* Test for any wide character that corresponds to a lowercase letter
119 or is one of a locale-specific set of wide characters for which
120 none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
121 extern int iswlower
__P ((wint_t __wc
));
123 /* Test for any printing wide character. */
124 extern int iswprint
__P ((wint_t __wc
));
126 /* Test for any printing wide character that is one of a
127 locale-specific et of wide characters for which neither `iswspace'
128 nor `iswalnum' is true. */
129 extern int iswpunct
__P ((wint_t __wc
));
131 /* Test for any wide character that corresponds to a locale-specific
132 set of wide characters for which none of `iswalnum', `iswgraph', or
133 `iswpunct' is true. */
134 extern int iswspace
__P ((wint_t __wc
));
136 /* Test for any wide character that corresponds to an uppercase letter
137 or is one of a locale-specific set of wide character for which none
138 of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
139 extern int iswupper
__P ((wint_t __wc
));
141 /* Test for any wide character that corresponds to a hexadecimal-digit
142 character equivalent to that performed be the functions described
143 in the previous subclause. */
144 extern int iswxdigit
__P ((wint_t __wc
));
147 * Extensible wide-character classification functions: 7.15.2.2.
150 /* Construct value that describes a class of wide characters identified
151 by the string argument PROPERTY. */
152 extern wctype_t wctype
__P ((__const
char *__property
));
154 /* Determine whether the wide-character WC has the property described by
156 extern int __iswctype
__P ((wint_t __wc
, wctype_t __desc
));
157 extern int iswctype
__P ((wint_t __wc
, wctype_t __desc
));
161 * Wide-character case-mapping functions: 7.15.3.1.
164 /* Converts an uppercase letter to the corresponding lowercase letter. */
165 extern wint_t towlower
__P ((wint_t __wc
));
167 /* Converts an lowercase letter to the corresponding uppercase letter. */
168 extern wint_t towupper
__P ((wint_t __wc
));
171 * Extensible wide-character mapping functions: 7.15.3.2.
174 /* Construct value that describes a mapping between wide characters
175 identified by the string argument PROPERTY. */
176 extern wctrans_t wctrans
__P ((__const
char *__property
));
178 /* Map the wide character WC using the mapping described by DESC. */
179 extern wint_t towctrans
__P ((wint_t __wc
, wctrans_t __desc
));
184 # define iswalnum(wc) __iswctype ((wc), _ISalnum)
185 # define iswalpha(wc) __iswctype ((wc), _ISalpha)
186 # define iswcntrl(wc) __iswctype ((wc), _IScntrl)
187 # define iswdigit(wc) __iswctype ((wc), _ISdigit)
188 # define iswlower(wc) __iswctype ((wc), _ISlower)
189 # define iswgraph(wc) __iswctype ((wc), _ISgraph)
190 # define iswprint(wc) __iswctype ((wc), _ISprint)
191 # define iswpunct(wc) __iswctype ((wc), _ISpunct)
192 # define iswspace(wc) __iswctype ((wc), _ISspace)
193 # define iswupper(wc) __iswctype ((wc), _ISupper)
194 # define iswxdigit(wc) __iswctype ((wc), _ISxdigit)
197 # define iswblank(wc) __iswctype ((wc), _ISblank)
200 /* Pointer to conversion tables. */
201 extern __const __int32_t
*__ctype_tolower
; /* Case conversions. */
202 extern __const __int32_t
*__ctype_toupper
; /* Case conversions. */
204 # define towlower(wc) towctrans ((wc), __ctype_tolower)
205 # define towupper(wc) towctrans ((wc), __ctype_toupper)
207 #endif /* Not __NO_WCTYPE. */
210 /* Declare the interface to extended locale model. */
211 # include <xlocale.h>
213 /* Test for any wide character for which `iswalpha' or `iswdigit' is
215 extern int __iswalnum_l
__P ((wint_t __wc
, __locale_t __locale
));
217 /* Test for any wide character for which `iswupper' or 'iswlower' is
218 true, or any wide character that is one of a locale-specific set of
219 wide-characters for which none of `iswcntrl', `iswdigit',
220 `iswpunct', or `iswspace' is true. */
221 extern int __iswalpha_l
__P ((wint_t __wc
, __locale_t __locale
));
223 /* Test for any control wide character. */
224 extern int __iswcntrl_l
__P ((wint_t __wc
, __locale_t __locale
));
226 /* Test for any wide character that corresponds to a decimal-digit
228 extern int __iswdigit_l
__P ((wint_t __wc
, __locale_t __locale
));
230 /* Test for any wide character for which `iswprint' is true and
231 `iswspace' is false. */
232 extern int __iswgraph_l
__P ((wint_t __wc
, __locale_t __locale
));
234 /* Test for any wide character that corresponds to a lowercase letter
235 or is one of a locale-specific set of wide characters for which
236 none of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
237 extern int __iswlower_l
__P ((wint_t __wc
, __locale_t __locale
));
239 /* Test for any printing wide character. */
240 extern int __iswprint_l
__P ((wint_t __wc
, __locale_t __locale
));
242 /* Test for any printing wide character that is one of a
243 locale-specific et of wide characters for which neither `iswspace'
244 nor `iswalnum' is true. */
245 extern int __iswpunct_l
__P ((wint_t __wc
, __locale_t __locale
));
247 /* Test for any wide character that corresponds to a locale-specific
248 set of wide characters for which none of `iswalnum', `iswgraph', or
249 `iswpunct' is true. */
250 extern int __iswspace_l
__P ((wint_t __wc
, __locale_t __locale
));
252 /* Test for any wide character that corresponds to an uppercase letter
253 or is one of a locale-specific set of wide character for which none
254 of `iswcntrl', `iswdigit', `iswpunct', or `iswspace' is true. */
255 extern int __iswupper_l
__P ((wint_t __wc
, __locale_t __locale
));
257 /* Test for any wide character that corresponds to a hexadecimal-digit
258 character equivalent to that performed be the functions described
259 in the previous subclause. */
260 extern int __iswxdigit_l
__P ((wint_t __wc
, __locale_t __locale
));
263 /* Determine whether the wide-character WC has the property described by
265 extern int __iswctype_l
__P ((wint_t __wc
, wctype_t __desc
,
270 * Wide-character case-mapping functions: 7.15.3.1.
273 /* Converts an uppercase letter to the corresponding lowercase letter. */
274 extern wint_t __towlower_l
__P ((wint_t __wc
, __locale_t locale
));
276 /* Converts an lowercase letter to the corresponding uppercase letter. */
277 extern wint_t __towupper_l
__P ((wint_t __wc
, __locale_t locale
));
279 /* Map the wide character WC using the mapping described by DESC. */
280 extern wint_t __towctrans_l
__P ((wint_t __wc
, wctrans_t __desc
,
285 # define __iswalnum_l(wc, loc) __iswctype_l ((wc), _ISalnum, (loc))
286 # define __iswalpha_l(wc, loc) __iswctype_l ((wc), _ISalpha, (loc))
287 # define __iswcntrl_l(wc, loc) __iswctype_l ((wc), _IScntrl, (loc))
288 # define __iswdigit_l(wc, loc) __iswctype_l ((wc), _ISdigit, (loc))
289 # define __iswlower_l(wc, loc) __iswctype_l ((wc), _ISlower, (loc))
290 # define __iswgraph_l(wc, loc) __iswctype_l ((wc), _ISgraph, (loc))
291 # define __iswprint_l(wc, loc) __iswctype_l ((wc), _ISprint, (loc))
292 # define __iswpunct_l(wc, loc) __iswctype_l ((wc), _ISpunct, (loc))
293 # define __iswspace_l(wc, loc) __iswctype_l ((wc), _ISspace, (loc))
294 # define __iswupper_l(wc, loc) __iswctype_l ((wc), _ISupper, (loc))
295 # define __iswxdigit_l(wc, loc) __iswctype_l ((wc), _ISxdigit, (loc))
297 # define __iswblank_l(wc, loc) __iswctype_l ((wc), _ISblank, (loc))
299 # define __towlower_l(wc, loc) __towctrans_l ((wc), (loc)->__ctype_tolower, \
301 # define __towupper_l(wc, loc) __towctrans_l ((wc), (loc)->__ctype_toupper, \
304 # endif /* Not __NO_WCTYPE. */
306 #endif /* Use GNU. */
310 #endif /* wctype.h */