Fix the last change. The variable still has to end in _data.
[glibc.git] / ctype / ctype.h
blobc17aaf171ce80fe587afd01bdafbc59628cbf084
1 /* Copyright (C) 1991,92,93,95,96,97,98,99,2001,02
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
21 * ISO C99 Standard 7.4: Character handling <ctype.h>
24 #ifndef _CTYPE_H
25 #define _CTYPE_H 1
27 #include <features.h>
28 #include <bits/types.h>
30 __BEGIN_DECLS
32 #ifndef _ISbit
33 /* These are all the characteristics of characters.
34 If there get to be more than 16 distinct characteristics,
35 many things must be changed that use `unsigned short int's.
37 The characteristics are stored always in network byte order (big
38 endian). We define the bit value interpretations here dependent on the
39 machine's byte order. */
41 # include <endian.h>
42 # if __BYTE_ORDER == __BIG_ENDIAN
43 # define _ISbit(bit) (1 << (bit))
44 # else /* __BYTE_ORDER == __LITTLE_ENDIAN */
45 # define _ISbit(bit) ((bit) < 8 ? ((1 << (bit)) << 8) : ((1 << (bit)) >> 8))
46 # endif
48 enum
50 _ISupper = _ISbit (0), /* UPPERCASE. */
51 _ISlower = _ISbit (1), /* lowercase. */
52 _ISalpha = _ISbit (2), /* Alphabetic. */
53 _ISdigit = _ISbit (3), /* Numeric. */
54 _ISxdigit = _ISbit (4), /* Hexadecimal numeric. */
55 _ISspace = _ISbit (5), /* Whitespace. */
56 _ISprint = _ISbit (6), /* Printing. */
57 _ISgraph = _ISbit (7), /* Graphical. */
58 _ISblank = _ISbit (8), /* Blank (usually SPC and TAB). */
59 _IScntrl = _ISbit (9), /* Control character. */
60 _ISpunct = _ISbit (10), /* Punctuation. */
61 _ISalnum = _ISbit (11) /* Alphanumeric. */
63 #endif /* ! _ISbit */
65 /* These are defined in ctype-info.c.
66 The declarations here must match those in localeinfo.h.
68 These point into arrays of 384, so they can be indexed by any `unsigned
69 char' value [0,255]; by EOF (-1); or by any `signed char' value
70 [-128,-1). ISO C requires that the ctype functions work for `unsigned
71 char' values and for EOF; we also support negative `signed char' values
72 for broken old programs. The case conversion arrays are of `int's
73 rather than `unsigned char's because tolower (EOF) must be EOF, which
74 doesn't fit into an `unsigned char'. But today more important is that
75 the arrays are also used for multi-byte character sets. */
76 extern __const unsigned short int *__ctype_b; /* Characteristics. */
77 extern __const __int32_t *__ctype_tolower; /* Case conversions. */
78 extern __const __int32_t *__ctype_toupper; /* Case conversions. */
80 #define __isctype(c, type) \
81 (__ctype_b[(int) (c)] & (unsigned short int) type)
83 #define __isascii(c) (((c) & ~0x7f) == 0) /* If C is a 7 bit value. */
84 #define __toascii(c) ((c) & 0x7f) /* Mask off high bits. */
86 #define __exctype(name) extern int name (int) __THROW
88 /* The following names are all functions:
89 int isCHARACTERISTIC(int c);
90 which return nonzero iff C has CHARACTERISTIC.
91 For the meaning of the characteristic names, see the `enum' above. */
92 __exctype (isalnum);
93 __exctype (isalpha);
94 __exctype (iscntrl);
95 __exctype (isdigit);
96 __exctype (islower);
97 __exctype (isgraph);
98 __exctype (isprint);
99 __exctype (ispunct);
100 __exctype (isspace);
101 __exctype (isupper);
102 __exctype (isxdigit);
104 #ifdef __USE_ISOC99
105 __exctype (isblank);
106 #endif
109 /* Return the lowercase version of C. */
110 extern int tolower (int __c) __THROW;
112 /* Return the uppercase version of C. */
113 extern int toupper (int __c) __THROW;
116 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
118 /* Return nonzero iff C is in the ASCII set
119 (i.e., is no more than 7 bits wide). */
120 extern int isascii (int __c) __THROW;
122 /* Return the part of C that is in the ASCII set
123 (i.e., the low-order 7 bits of C). */
124 extern int toascii (int __c) __THROW;
126 /* These are the same as `toupper' and `tolower' except that they do not
127 check the argument for being in the range of a `char'. */
128 __exctype (_toupper);
129 __exctype (_tolower);
130 #endif /* Use SVID or use misc. */
132 /* This code is needed for the optimized mapping functions. */
133 #define __tobody(c, f, a, args) \
134 (__extension__ \
135 ({ int __res; \
136 if (sizeof (c) > 1) \
138 if (__builtin_constant_p (c)) \
140 int __c = (c); \
141 __res = __c < -128 || __c > 255 ? __c : a[__c]; \
143 else \
144 __res = f args; \
146 else \
147 __res = a[(int) (c)]; \
148 __res; }))
150 #ifndef __NO_CTYPE
151 # define isalnum(c) __isctype((c), _ISalnum)
152 # define isalpha(c) __isctype((c), _ISalpha)
153 # define iscntrl(c) __isctype((c), _IScntrl)
154 # define isdigit(c) __isctype((c), _ISdigit)
155 # define islower(c) __isctype((c), _ISlower)
156 # define isgraph(c) __isctype((c), _ISgraph)
157 # define isprint(c) __isctype((c), _ISprint)
158 # define ispunct(c) __isctype((c), _ISpunct)
159 # define isspace(c) __isctype((c), _ISspace)
160 # define isupper(c) __isctype((c), _ISupper)
161 # define isxdigit(c) __isctype((c), _ISxdigit)
163 # ifdef __USE_ISOC99
164 # define isblank(c) __isctype((c), _ISblank)
165 # endif
167 # ifdef __USE_EXTERN_INLINES
168 extern __inline int
169 tolower (int __c) __THROW
171 return __c >= -128 && __c < 256 ? __ctype_tolower[__c] : __c;
174 extern __inline int
175 toupper (int __c) __THROW
177 return __c >= -128 && __c < 256 ? __ctype_toupper[__c] : __c;
179 # endif
181 # if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
182 # define tolower(c) __tobody (c, tolower, __ctype_tolower, (c))
183 # define toupper(c) __tobody (c, toupper, __ctype_toupper, (c))
184 # endif /* Optimizing gcc */
186 # if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
187 # define isascii(c) __isascii (c)
188 # define toascii(c) __toascii (c)
190 # define _tolower(c) ((int) __ctype_tolower[(int) (c)])
191 # define _toupper(c) ((int) __ctype_toupper[(int) (c)])
192 # endif
194 #endif /* Not __NO_CTYPE. */
197 #ifdef __USE_GNU
198 /* The concept of one static locale per category is not very well
199 thought out. Many applications will need to process its data using
200 information from several different locales. Another application is
201 the implementation of the internationalization handling in the
202 upcoming ISO C++ standard library. To support this another set of
203 the functions using locale data exist which have an additional
204 argument.
206 Attention: all these functions are *not* standardized in any form.
207 This is a proof-of-concept implementation. */
209 /* Structure for reentrant locale using functions. This is an
210 (almost) opaque type for the user level programs. */
211 # include <xlocale.h>
213 /* These definitions are similar to the ones above but all functions
214 take as an argument a handle for the locale which shall be used. */
215 # define __isctype_l(c, type, locale) \
216 ((locale)->__ctype_b[(int) (c)] & (unsigned short int) type)
218 # define __exctype_l(name) \
219 extern int name (int, __locale_t) __THROW; \
220 extern int __##name (int, __locale_t) __THROW
222 /* The following names are all functions:
223 int isCHARACTERISTIC(int c, locale_t *locale);
224 which return nonzero iff C has CHARACTERISTIC.
225 For the meaning of the characteristic names, see the `enum' above. */
226 __exctype_l (isalnum_l);
227 __exctype_l (isalpha_l);
228 __exctype_l (iscntrl_l);
229 __exctype_l (isdigit_l);
230 __exctype_l (islower_l);
231 __exctype_l (isgraph_l);
232 __exctype_l (isprint_l);
233 __exctype_l (ispunct_l);
234 __exctype_l (isspace_l);
235 __exctype_l (isupper_l);
236 __exctype_l (isxdigit_l);
238 __exctype_l (isblank_l);
241 /* Return the lowercase version of C in locale L. */
242 extern int __tolower_l (int __c, __locale_t __l) __THROW;
243 extern int tolower_l (int __c, __locale_t __l) __THROW;
245 /* Return the uppercase version of C. */
246 extern int __toupper_l (int __c, __locale_t __l) __THROW;
247 extern int toupper_l (int __c, __locale_t __l) __THROW;
249 # if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
250 # define __tolower_l(c, locale) \
251 __tobody (c, __tolower_l, (locale)->__ctype_tolower, (c, locale))
252 # define __toupper_l(c, locale) \
253 __tobody (c, __toupper_l, (locale)->__ctype_toupper, (c, locale))
254 # define tolower_l(c, locale) __tolower_l ((c), (locale))
255 # define toupper_l(c, locale) __toupper_l ((c), (locale))
256 # endif /* Optimizing gcc */
259 # ifndef __NO_CTYPE
260 # define __isalnum_l(c,l) __isctype_l((c), _ISalnum, (l))
261 # define __isalpha_l(c,l) __isctype_l((c), _ISalpha, (l))
262 # define __iscntrl_l(c,l) __isctype_l((c), _IScntrl, (l))
263 # define __isdigit_l(c,l) __isctype_l((c), _ISdigit, (l))
264 # define __islower_l(c,l) __isctype_l((c), _ISlower, (l))
265 # define __isgraph_l(c,l) __isctype_l((c), _ISgraph, (l))
266 # define __isprint_l(c,l) __isctype_l((c), _ISprint, (l))
267 # define __ispunct_l(c,l) __isctype_l((c), _ISpunct, (l))
268 # define __isspace_l(c,l) __isctype_l((c), _ISspace, (l))
269 # define __isupper_l(c,l) __isctype_l((c), _ISupper, (l))
270 # define __isxdigit_l(c,l) __isctype_l((c), _ISxdigit, (l))
272 # define __isblank_l(c,l) __isctype_l((c), _ISblank, (l))
274 # if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
275 # define __isascii_l(c,l) ((l), __isascii (c))
276 # define __toascii_l(c,l) ((l), __toascii (c))
277 # endif
279 # define isalnum_l(c,l) __isalnum_l ((c), (l))
280 # define isalpha_l(c,l) __isalpha_l ((c), (l))
281 # define iscntrl_l(c,l) __iscntrl_l ((c), (l))
282 # define isdigit_l(c,l) __isdigit_l ((c), (l))
283 # define islower_l(c,l) __islower_l ((c), (l))
284 # define isgraph_l(c,l) __isgraph_l ((c), (l))
285 # define isprint_l(c,l) __isprint_l ((c), (l))
286 # define ispunct_l(c,l) __ispunct_l ((c), (l))
287 # define isspace_l(c,l) __isspace_l ((c), (l))
288 # define isupper_l(c,l) __isupper_l ((c), (l))
289 # define isxdigit_l(c,l) __isxdigit_l ((c), (l))
291 # define isblank_l(c,l) __isblank_l ((c), (l))
293 # if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
294 # define isascii_l(c,l) __isascii ((c), (l))
295 # define toascii_l(c,l) __toascii ((c), (l))
296 # endif
298 # endif /* Not __NO_CTYPE. */
300 #endif /* Use GNU. */
302 __END_DECLS
304 #endif /* ctype.h */