ctype.h
001:
002:
003:
004:
005:
006:
007:
008:
009:
010:
011:
012:
013:
014:
015:
016:
017:
018:
019:
020:
021:
022:
023:
024: #ifndef _CTYPE_H
025: #define _CTYPE_H 1
026:
027: #include <features.h>
028: #include <bits/types.h>
029:
030: __BEGIN_DECLS
031:
032: #ifndef _ISbit
033:
034:
035:
036:
037:
038:
039:
040:
041: # include <endian.h>
042: # if __BYTE_ORDER == __BIG_ENDIAN
043: # define _ISbit(bit) (1 << (bit))
044: # else
045: # define _ISbit(bit) ((bit) < 8 ? ((1 << (bit)) << 8) : ((1 << (bit)) >> 8))
046: # endif
047:
048: enum
049: {
050: _ISupper = _ISbit (0),
051: _ISlower = _ISbit (1),
052: _ISalpha = _ISbit (2),
053: _ISdigit = _ISbit (3),
054: _ISxdigit = _ISbit (4),
055: _ISspace = _ISbit (5),
056: _ISprint = _ISbit (6),
057: _ISgraph = _ISbit (7),
058: _ISblank = _ISbit (8),
059: _IScntrl = _ISbit (9),
060: _ISpunct = _ISbit (10),
061: _ISalnum = _ISbit (11)
062: };
063: #endif
064:
065:
066:
067:
068:
069:
070:
071:
072:
073:
074:
075:
076:
077:
078:
079:
080:
081: extern __const unsigned short int **__ctype_b_loc (void)
082: __THROW __attribute__ ((__const));
083: extern __const __int32_t **__ctype_tolower_loc (void)
084: __THROW __attribute__ ((__const));
085: extern __const __int32_t **__ctype_toupper_loc (void)
086: __THROW __attribute__ ((__const));
087:
088:
089: #ifndef __cplusplus
090: # define __isctype(c, type) \
091: ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) type)
092: #elif defined __USE_EXTERN_INLINES
093: # define __isctype_f(type) \
094: __extern_inline int \
095: is##type (int __c) __THROW \
096: { \
097: return (*__ctype_b_loc ())[(int) (__c)] & (unsigned short int) _IS##type; \
098: }
099: #endif
100:
101: #define __isascii(c) (((c) & ~0x7f) == 0)
102: #define __toascii(c) ((c) & 0x7f)
103:
104: #define __exctype(name) extern int name (int) __THROW
105:
106: __BEGIN_NAMESPACE_STD
107:
108:
109:
110:
111:
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:
124:
125:
126: extern int tolower (int __c) __THROW;
127:
128:
129: extern int toupper (int __c) __THROW;
130:
131: __END_NAMESPACE_STD
132:
133:
134:
135: #ifdef __USE_ISOC99
136: __BEGIN_NAMESPACE_C99
137:
138: __exctype (isblank);
139:
140: __END_NAMESPACE_C99
141: #endif
142:
143: #ifdef __USE_GNU
144:
145: extern int isctype (int __c, int __mask) __THROW;
146: #endif
147:
148: #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
149:
150:
151:
152: extern int isascii (int __c) __THROW;
153:
154:
155:
156: extern int toascii (int __c) __THROW;
157:
158:
159:
160: __exctype (_toupper);
161: __exctype (_tolower);
162: #endif
163:
164:
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); \
173: __res = __c < -128 || __c > 255 ? __c : (a)[__c]; \
174: } \
175: else \
176: __res = f args; \
177: } \
178: else \
179: __res = (a)[(int) (c)]; \
180: __res; }))
181:
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
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)
210: # ifdef __USE_ISOC99
211: # define isblank(c) __isctype((c), _ISblank)
212: # endif
213: # endif
214:
215: # ifdef __USE_EXTERN_INLINES
216: __extern_inline int
217: __NTH (tolower (int __c))
218: {
219: return __c >= -128 && __c < 256 ? (*__ctype_tolower_loc ())[__c] : __c;
220: }
221:
222: __extern_inline int
223: __NTH (toupper (int __c))
224: {
225: return __c >= -128 && __c < 256 ? (*__ctype_toupper_loc ())[__c] : __c;
226: }
227: # endif
228:
229: # if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
230: # define tolower(c) __tobody (c, tolower, *__ctype_tolower_loc (), (c))
231: # define toupper(c) __tobody (c, toupper, *__ctype_toupper_loc (), (c))
232: # endif
233:
234: # if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
235: # define isascii(c) __isascii (c)
236: # define toascii(c) __toascii (c)
237:
238: # define _tolower(c) ((int) (*__ctype_tolower_loc ())[(int) (c)])
239: # define _toupper(c) ((int) (*__ctype_toupper_loc ())[(int) (c)])
240: # endif
241:
242: #endif
243:
244:
245: #ifdef __USE_XOPEN2K8
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259: # include <xlocale.h>
260:
261:
262:
263: # define __isctype_l(c, type, locale) \
264: ((locale)->__ctype_b[(int) (c)] & (unsigned short int) type)
265:
266: # define __exctype_l(name) \
267: extern int name (int, __locale_t) __THROW
268:
269:
270:
271:
272:
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);
284:
285: __exctype_l (isblank_l);
286:
287:
288:
289: extern int __tolower_l (int __c, __locale_t __l) __THROW;
290: extern int tolower_l (int __c, __locale_t __l) __THROW;
291:
292:
293: extern int __toupper_l (int __c, __locale_t __l) __THROW;
294: extern int toupper_l (int __c, __locale_t __l) __THROW;
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))
301: # define tolower_l(c, locale) __tolower_l ((c), (locale))
302: # define toupper_l(c, locale) __toupper_l ((c), (locale))
303: # endif
304:
305:
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))
318:
319: # define __isblank_l(c,l) __isctype_l((c), _ISblank, (l))
320:
321: # if defined __USE_SVID || defined __USE_MISC
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:
340: # if defined __USE_SVID || defined __USE_MISC
341: # define isascii_l(c,l) __isascii_l ((c), (l))
342: # define toascii_l(c,l) __toascii_l ((c), (l))
343: # endif
344:
345: # endif
346:
347: #endif
348:
349: __END_DECLS
350:
351: #endif
352:
© Andrew Scott 2006 -
2024,
All Rights Reserved