]>
Commit | Line | Data |
---|---|---|
a784e502 | 1 | /* Copyright (C) 1991,92,93,95,96,97,98,99,2001,2002,2004,2007-2009,2011,2012 |
396a21b1 | 2 | Free Software Foundation, Inc. |
ba1ffaa1 | 3 | This file is part of the GNU C Library. |
28f540f4 | 4 | |
ba1ffaa1 | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
28f540f4 | 9 | |
ba1ffaa1 UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
28f540f4 | 14 | |
41bdb6e2 AJ |
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. */ | |
28f540f4 RM |
19 | |
20 | /* | |
d1646309 | 21 | * ISO C99 Standard 7.4: Character handling <ctype.h> |
28f540f4 RM |
22 | */ |
23 | ||
24 | #ifndef _CTYPE_H | |
28f540f4 | 25 | #define _CTYPE_H 1 |
5107cf1d | 26 | |
28f540f4 | 27 | #include <features.h> |
36775c3b | 28 | #include <bits/types.h> |
28f540f4 RM |
29 | |
30 | __BEGIN_DECLS | |
31 | ||
19bc17a9 | 32 | #ifndef _ISbit |
28635115 RM |
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. | |
36 | ||
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. */ | |
40 | ||
dfd2257a UD |
41 | # include <endian.h> |
42 | # if __BYTE_ORDER == __BIG_ENDIAN | |
6685edd3 | 43 | # define _ISbit(bit) (1 << (bit)) |
dfd2257a | 44 | # else /* __BYTE_ORDER == __LITTLE_ENDIAN */ |
6685edd3 | 45 | # define _ISbit(bit) ((bit) < 8 ? ((1 << (bit)) << 8) : ((1 << (bit)) >> 8)) |
dfd2257a | 46 | # endif |
28635115 | 47 | |
28f540f4 RM |
48 | enum |
49 | { | |
28635115 RM |
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. */ | |
19bc17a9 | 61 | _ISalnum = _ISbit (11) /* Alphanumeric. */ |
28f540f4 | 62 | }; |
19bc17a9 | 63 | #endif /* ! _ISbit */ |
28f540f4 | 64 | |
d20fec5d UD |
65 | /* These are defined in ctype-info.c. |
66 | The declarations here must match those in localeinfo.h. | |
67 | ||
cf684340 RM |
68 | In the thread-specific locale model (see `uselocale' in <locale.h>) |
69 | we cannot use global variables for these as was done in the past. | |
70 | Instead, the following accessor functions return the address of | |
71 | each variable, which is local to the current thread if multithreaded. | |
72 | ||
d20fec5d UD |
73 | These point into arrays of 384, so they can be indexed by any `unsigned |
74 | char' value [0,255]; by EOF (-1); or by any `signed char' value | |
75 | [-128,-1). ISO C requires that the ctype functions work for `unsigned | |
76 | char' values and for EOF; we also support negative `signed char' values | |
77 | for broken old programs. The case conversion arrays are of `int's | |
78 | rather than `unsigned char's because tolower (EOF) must be EOF, which | |
79 | doesn't fit into an `unsigned char'. But today more important is that | |
80 | the arrays are also used for multi-byte character sets. */ | |
a784e502 UD |
81 | extern const unsigned short int **__ctype_b_loc (void) |
82 | __THROW __attribute__ ((__const__)); | |
83 | extern const __int32_t **__ctype_tolower_loc (void) | |
84 | __THROW __attribute__ ((__const__)); | |
85 | extern const __int32_t **__ctype_toupper_loc (void) | |
86 | __THROW __attribute__ ((__const__)); | |
d20fec5d | 87 | |
396a21b1 UD |
88 | |
89 | #ifndef __cplusplus | |
90 | # define __isctype(c, type) \ | |
cf684340 | 91 | ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) type) |
396a21b1 UD |
92 | #elif defined __USE_EXTERN_INLINES |
93 | # define __isctype_f(type) \ | |
94 | __extern_inline int \ | |
538faaa7 | 95 | is##type (int __c) __THROW \ |
396a21b1 UD |
96 | { \ |
97 | return (*__ctype_b_loc ())[(int) (__c)] & (unsigned short int) _IS##type; \ | |
98 | } | |
99 | #endif | |
d20fec5d | 100 | |
2303f5fd UD |
101 | #define __isascii(c) (((c) & ~0x7f) == 0) /* If C is a 7 bit value. */ |
102 | #define __toascii(c) ((c) & 0x7f) /* Mask off high bits. */ | |
28f540f4 | 103 | |
c1422e5b | 104 | #define __exctype(name) extern int name (int) __THROW |
28f540f4 | 105 | |
7a5affeb | 106 | __BEGIN_NAMESPACE_STD |
0f283ffc | 107 | |
28f540f4 RM |
108 | /* The following names are all functions: |
109 | int isCHARACTERISTIC(int c); | |
110 | which return nonzero iff C has CHARACTERISTIC. | |
111 | For the meaning of the characteristic names, see the `enum' above. */ | |
112 | __exctype (isalnum); | |
113 | __exctype (isalpha); | |
114 | __exctype (iscntrl); | |
115 | __exctype (isdigit); | |
116 | __exctype (islower); | |
117 | __exctype (isgraph); | |
118 | __exctype (isprint); | |
119 | __exctype (ispunct); | |
120 | __exctype (isspace); | |
121 | __exctype (isupper); | |
122 | __exctype (isxdigit); | |
123 | ||
28f540f4 RM |
124 | |
125 | /* Return the lowercase version of C. */ | |
c1422e5b | 126 | extern int tolower (int __c) __THROW; |
28f540f4 RM |
127 | |
128 | /* Return the uppercase version of C. */ | |
c1422e5b | 129 | extern int toupper (int __c) __THROW; |
28f540f4 | 130 | |
7a5affeb UD |
131 | __END_NAMESPACE_STD |
132 | ||
133 | ||
134 | /* ISO C99 introduced one new function. */ | |
135 | #ifdef __USE_ISOC99 | |
136 | __BEGIN_NAMESPACE_C99 | |
137 | ||
138 | __exctype (isblank); | |
139 | ||
140 | __END_NAMESPACE_C99 | |
141 | #endif | |
28f540f4 | 142 | |
fa1861d9 UD |
143 | #ifdef __USE_GNU |
144 | /* Test C for a set of character classes according to MASK. */ | |
145 | extern int isctype (int __c, int __mask) __THROW; | |
146 | #endif | |
147 | ||
dfd2257a | 148 | #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN |
28f540f4 RM |
149 | |
150 | /* Return nonzero iff C is in the ASCII set | |
151 | (i.e., is no more than 7 bits wide). */ | |
c1422e5b | 152 | extern int isascii (int __c) __THROW; |
28f540f4 RM |
153 | |
154 | /* Return the part of C that is in the ASCII set | |
155 | (i.e., the low-order 7 bits of C). */ | |
c1422e5b | 156 | extern int toascii (int __c) __THROW; |
28f540f4 | 157 | |
8d8c6efa UD |
158 | /* These are the same as `toupper' and `tolower' except that they do not |
159 | check the argument for being in the range of a `char'. */ | |
28f540f4 RM |
160 | __exctype (_toupper); |
161 | __exctype (_tolower); | |
70b2845f | 162 | #endif /* Use SVID or use misc. */ |
28f540f4 | 163 | |
c1422e5b UD |
164 | /* This code is needed for the optimized mapping functions. */ |
165 | #define __tobody(c, f, a, args) \ | |
166 | (__extension__ \ | |
167 | ({ int __res; \ | |
168 | if (sizeof (c) > 1) \ | |
169 | { \ | |
170 | if (__builtin_constant_p (c)) \ | |
171 | { \ | |
172 | int __c = (c); \ | |
0f283ffc | 173 | __res = __c < -128 || __c > 255 ? __c : (a)[__c]; \ |
c1422e5b UD |
174 | } \ |
175 | else \ | |
176 | __res = f args; \ | |
177 | } \ | |
178 | else \ | |
0f283ffc | 179 | __res = (a)[(int) (c)]; \ |
c1422e5b UD |
180 | __res; })) |
181 | ||
396a21b1 UD |
182 | #if !defined __NO_CTYPE |
183 | # ifdef __isctype_f | |
184 | __isctype_f (alnum) | |
185 | __isctype_f (alpha) | |
186 | __isctype_f (cntrl) | |
187 | __isctype_f (digit) | |
188 | __isctype_f (lower) | |
189 | __isctype_f (graph) | |
190 | __isctype_f (print) | |
191 | __isctype_f (punct) | |
192 | __isctype_f (space) | |
193 | __isctype_f (upper) | |
194 | __isctype_f (xdigit) | |
195 | # ifdef __USE_ISOC99 | |
196 | __isctype_f (blank) | |
197 | # endif | |
198 | # elif defined __isctype | |
d20fec5d UD |
199 | # define isalnum(c) __isctype((c), _ISalnum) |
200 | # define isalpha(c) __isctype((c), _ISalpha) | |
201 | # define iscntrl(c) __isctype((c), _IScntrl) | |
202 | # define isdigit(c) __isctype((c), _ISdigit) | |
203 | # define islower(c) __isctype((c), _ISlower) | |
204 | # define isgraph(c) __isctype((c), _ISgraph) | |
205 | # define isprint(c) __isctype((c), _ISprint) | |
206 | # define ispunct(c) __isctype((c), _ISpunct) | |
207 | # define isspace(c) __isctype((c), _ISspace) | |
208 | # define isupper(c) __isctype((c), _ISupper) | |
209 | # define isxdigit(c) __isctype((c), _ISxdigit) | |
396a21b1 UD |
210 | # ifdef __USE_ISOC99 |
211 | # define isblank(c) __isctype((c), _ISblank) | |
212 | # endif | |
d20fec5d UD |
213 | # endif |
214 | ||
215 | # ifdef __USE_EXTERN_INLINES | |
b037a293 | 216 | __extern_inline int |
f377d022 | 217 | __NTH (tolower (int __c)) |
d20fec5d | 218 | { |
cf684340 | 219 | return __c >= -128 && __c < 256 ? (*__ctype_tolower_loc ())[__c] : __c; |
d20fec5d UD |
220 | } |
221 | ||
b037a293 | 222 | __extern_inline int |
f377d022 | 223 | __NTH (toupper (int __c)) |
d20fec5d | 224 | { |
cf684340 | 225 | return __c >= -128 && __c < 256 ? (*__ctype_toupper_loc ())[__c] : __c; |
d20fec5d UD |
226 | } |
227 | # endif | |
228 | ||
229 | # if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus | |
cf684340 RM |
230 | # define tolower(c) __tobody (c, tolower, *__ctype_tolower_loc (), (c)) |
231 | # define toupper(c) __tobody (c, toupper, *__ctype_toupper_loc (), (c)) | |
d20fec5d UD |
232 | # endif /* Optimizing gcc */ |
233 | ||
c813f986 UD |
234 | # if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN |
235 | # define isascii(c) __isascii (c) | |
236 | # define toascii(c) __toascii (c) | |
d20fec5d | 237 | |
cf684340 RM |
238 | # define _tolower(c) ((int) (*__ctype_tolower_loc ())[(int) (c)]) |
239 | # define _toupper(c) ((int) (*__ctype_toupper_loc ())[(int) (c)]) | |
c813f986 | 240 | # endif |
d20fec5d | 241 | |
28f540f4 RM |
242 | #endif /* Not __NO_CTYPE. */ |
243 | ||
c84142e8 | 244 | |
77db439e | 245 | #ifdef __USE_XOPEN2K8 |
c84142e8 UD |
246 | /* The concept of one static locale per category is not very well |
247 | thought out. Many applications will need to process its data using | |
248 | information from several different locales. Another application is | |
249 | the implementation of the internationalization handling in the | |
250 | upcoming ISO C++ standard library. To support this another set of | |
251 | the functions using locale data exist which have an additional | |
252 | argument. | |
253 | ||
254 | Attention: all these functions are *not* standardized in any form. | |
255 | This is a proof-of-concept implementation. */ | |
256 | ||
257 | /* Structure for reentrant locale using functions. This is an | |
258 | (almost) opaque type for the user level programs. */ | |
259 | # include <xlocale.h> | |
260 | ||
261 | /* These definitions are similar to the ones above but all functions | |
262 | take as an argument a handle for the locale which shall be used. */ | |
c1422e5b | 263 | # define __isctype_l(c, type, locale) \ |
c84142e8 UD |
264 | ((locale)->__ctype_b[(int) (c)] & (unsigned short int) type) |
265 | ||
1ab62b32 | 266 | # define __exctype_l(name) \ |
da4cfe38 | 267 | extern int name (int, __locale_t) __THROW |
c84142e8 UD |
268 | |
269 | /* The following names are all functions: | |
270 | int isCHARACTERISTIC(int c, locale_t *locale); | |
271 | which return nonzero iff C has CHARACTERISTIC. | |
272 | For the meaning of the characteristic names, see the `enum' above. */ | |
1ab62b32 RM |
273 | __exctype_l (isalnum_l); |
274 | __exctype_l (isalpha_l); | |
275 | __exctype_l (iscntrl_l); | |
276 | __exctype_l (isdigit_l); | |
277 | __exctype_l (islower_l); | |
278 | __exctype_l (isgraph_l); | |
279 | __exctype_l (isprint_l); | |
280 | __exctype_l (ispunct_l); | |
281 | __exctype_l (isspace_l); | |
282 | __exctype_l (isupper_l); | |
283 | __exctype_l (isxdigit_l); | |
c84142e8 | 284 | |
1ab62b32 | 285 | __exctype_l (isblank_l); |
c84142e8 UD |
286 | |
287 | ||
288 | /* Return the lowercase version of C in locale L. */ | |
c1422e5b | 289 | extern int __tolower_l (int __c, __locale_t __l) __THROW; |
1ab62b32 | 290 | extern int tolower_l (int __c, __locale_t __l) __THROW; |
c84142e8 UD |
291 | |
292 | /* Return the uppercase version of C. */ | |
c1422e5b | 293 | extern int __toupper_l (int __c, __locale_t __l) __THROW; |
1ab62b32 | 294 | extern int toupper_l (int __c, __locale_t __l) __THROW; |
c1422e5b UD |
295 | |
296 | # if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus | |
297 | # define __tolower_l(c, locale) \ | |
298 | __tobody (c, __tolower_l, (locale)->__ctype_tolower, (c, locale)) | |
299 | # define __toupper_l(c, locale) \ | |
300 | __tobody (c, __toupper_l, (locale)->__ctype_toupper, (c, locale)) | |
1ab62b32 RM |
301 | # define tolower_l(c, locale) __tolower_l ((c), (locale)) |
302 | # define toupper_l(c, locale) __toupper_l ((c), (locale)) | |
c1422e5b | 303 | # endif /* Optimizing gcc */ |
c84142e8 UD |
304 | |
305 | ||
dfd2257a UD |
306 | # ifndef __NO_CTYPE |
307 | # define __isalnum_l(c,l) __isctype_l((c), _ISalnum, (l)) | |
308 | # define __isalpha_l(c,l) __isctype_l((c), _ISalpha, (l)) | |
309 | # define __iscntrl_l(c,l) __isctype_l((c), _IScntrl, (l)) | |
310 | # define __isdigit_l(c,l) __isctype_l((c), _ISdigit, (l)) | |
311 | # define __islower_l(c,l) __isctype_l((c), _ISlower, (l)) | |
312 | # define __isgraph_l(c,l) __isctype_l((c), _ISgraph, (l)) | |
313 | # define __isprint_l(c,l) __isctype_l((c), _ISprint, (l)) | |
314 | # define __ispunct_l(c,l) __isctype_l((c), _ISpunct, (l)) | |
315 | # define __isspace_l(c,l) __isctype_l((c), _ISspace, (l)) | |
316 | # define __isupper_l(c,l) __isctype_l((c), _ISupper, (l)) | |
317 | # define __isxdigit_l(c,l) __isctype_l((c), _ISxdigit, (l)) | |
c84142e8 | 318 | |
dfd2257a UD |
319 | # define __isblank_l(c,l) __isctype_l((c), _ISblank, (l)) |
320 | ||
77db439e | 321 | # if defined __USE_SVID || defined __USE_MISC |
1ab62b32 RM |
322 | # define __isascii_l(c,l) ((l), __isascii (c)) |
323 | # define __toascii_l(c,l) ((l), __toascii (c)) | |
324 | # endif | |
325 | ||
326 | # define isalnum_l(c,l) __isalnum_l ((c), (l)) | |
327 | # define isalpha_l(c,l) __isalpha_l ((c), (l)) | |
328 | # define iscntrl_l(c,l) __iscntrl_l ((c), (l)) | |
329 | # define isdigit_l(c,l) __isdigit_l ((c), (l)) | |
330 | # define islower_l(c,l) __islower_l ((c), (l)) | |
331 | # define isgraph_l(c,l) __isgraph_l ((c), (l)) | |
332 | # define isprint_l(c,l) __isprint_l ((c), (l)) | |
333 | # define ispunct_l(c,l) __ispunct_l ((c), (l)) | |
334 | # define isspace_l(c,l) __isspace_l ((c), (l)) | |
335 | # define isupper_l(c,l) __isupper_l ((c), (l)) | |
336 | # define isxdigit_l(c,l) __isxdigit_l ((c), (l)) | |
337 | ||
338 | # define isblank_l(c,l) __isblank_l ((c), (l)) | |
339 | ||
77db439e | 340 | # if defined __USE_SVID || defined __USE_MISC |
da4cfe38 RM |
341 | # define isascii_l(c,l) __isascii_l ((c), (l)) |
342 | # define toascii_l(c,l) __toascii_l ((c), (l)) | |
dfd2257a UD |
343 | # endif |
344 | ||
345 | # endif /* Not __NO_CTYPE. */ | |
c84142e8 | 346 | |
77db439e | 347 | #endif /* Use POSIX 2008. */ |
c84142e8 | 348 | |
28f540f4 RM |
349 | __END_DECLS |
350 | ||
351 | #endif /* ctype.h */ |