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