Update.
[glibc.git] / ctype / ctype.h
blobfd4f9e8ca9bc5718632469a71e686700d1163d82
1 /* Copyright (C) 1991,92,93,95,96,97,98,99 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 4.3: CHARACTER HANDLING <ctype.h>
23 #ifndef _CTYPE_H
24 #define _CTYPE_H 1
26 #include <features.h>
27 #include <bits/types.h>
29 __BEGIN_DECLS
31 #ifndef _ISbit
32 /* These are all the characteristics of characters.
33 If there get to be more than 16 distinct characteristics,
34 many things must be changed that use `unsigned short int's.
36 The characteristics are stored always in network byte order (big
37 endian). We define the bit value interpretations here dependent on the
38 machine's byte order. */
40 # include <endian.h>
41 # if __BYTE_ORDER == __BIG_ENDIAN
42 # define _ISbit(bit) (1 << (bit))
43 # else /* __BYTE_ORDER == __LITTLE_ENDIAN */
44 # define _ISbit(bit) ((bit) < 8 ? ((1 << (bit)) << 8) : ((1 << (bit)) >> 8))
45 # endif
47 enum
49 _ISupper = _ISbit (0), /* UPPERCASE. */
50 _ISlower = _ISbit (1), /* lowercase. */
51 _ISalpha = _ISbit (2), /* Alphabetic. */
52 _ISdigit = _ISbit (3), /* Numeric. */
53 _ISxdigit = _ISbit (4), /* Hexadecimal numeric. */
54 _ISspace = _ISbit (5), /* Whitespace. */
55 _ISprint = _ISbit (6), /* Printing. */
56 _ISgraph = _ISbit (7), /* Graphical. */
57 _ISblank = _ISbit (8), /* Blank (usually SPC and TAB). */
58 _IScntrl = _ISbit (9), /* Control character. */
59 _ISpunct = _ISbit (10), /* Punctuation. */
60 _ISalnum = _ISbit (11) /* Alphanumeric. */
62 #endif /* ! _ISbit */
64 /* These are defined in ctype-info.c.
65 The declarations here must match those in localeinfo.h.
67 These point into arrays of 384, so they can be indexed by any `unsigned
68 char' value [0,255]; by EOF (-1); or by any `signed char' value
69 [-128,-1). ISO C requires that the ctype functions work for `unsigned
70 char' values and for EOF; we also support negative `signed char' values
71 for broken old programs. The case conversion arrays are of `int's
72 rather than `unsigned char's because tolower (EOF) must be EOF, which
73 doesn't fit into an `unsigned char'. But today more important is that
74 the arrays are also used for multi-byte character sets. */
75 extern __const unsigned short int *__ctype_b; /* Characteristics. */
76 extern __const __int32_t *__ctype_tolower; /* Case conversions. */
77 extern __const __int32_t *__ctype_toupper; /* Case conversions. */
79 #define __isctype(c, type) \
80 (__ctype_b[(int) (c)] & (unsigned short int) type)
82 #define __isascii(c) (((c) & ~0x7f) == 0) /* If C is a 7 bit value. */
83 #define __toascii(c) ((c) & 0x7f) /* Mask off high bits. */
85 #define __exctype(name) extern int name __P ((int))
87 /* The following names are all functions:
88 int isCHARACTERISTIC(int c);
89 which return nonzero iff C has CHARACTERISTIC.
90 For the meaning of the characteristic names, see the `enum' above. */
91 __exctype (isalnum);
92 __exctype (isalpha);
93 __exctype (iscntrl);
94 __exctype (isdigit);
95 __exctype (islower);
96 __exctype (isgraph);
97 __exctype (isprint);
98 __exctype (ispunct);
99 __exctype (isspace);
100 __exctype (isupper);
101 __exctype (isxdigit);
103 #ifdef __USE_GNU
104 __exctype (isblank);
105 #endif
108 /* Return the lowercase version of C. */
109 extern int tolower __P ((int __c));
111 /* Return the uppercase version of C. */
112 extern int toupper __P ((int __c));
115 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
117 /* Return nonzero iff C is in the ASCII set
118 (i.e., is no more than 7 bits wide). */
119 extern int isascii __P ((int __c));
121 /* Return the part of C that is in the ASCII set
122 (i.e., the low-order 7 bits of C). */
123 extern int toascii __P ((int __c));
125 #endif /* Use SVID or use misc. */
127 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
128 /* These are the same as `toupper' and `tolower' except that they do not
129 check the argument for being in the range of a `char'. */
130 __exctype (_toupper);
131 __exctype (_tolower);
132 #endif
134 #ifndef __NO_CTYPE
135 # define isalnum(c) __isctype((c), _ISalnum)
136 # define isalpha(c) __isctype((c), _ISalpha)
137 # define iscntrl(c) __isctype((c), _IScntrl)
138 # define isdigit(c) __isctype((c), _ISdigit)
139 # define islower(c) __isctype((c), _ISlower)
140 # define isgraph(c) __isctype((c), _ISgraph)
141 # define isprint(c) __isctype((c), _ISprint)
142 # define ispunct(c) __isctype((c), _ISpunct)
143 # define isspace(c) __isctype((c), _ISspace)
144 # define isupper(c) __isctype((c), _ISupper)
145 # define isxdigit(c) __isctype((c), _ISxdigit)
147 #ifdef __USE_GNU
148 # define isblank(c) __isctype((c), _ISblank)
149 #endif
151 #if defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ \
152 && defined __USE_EXTERN_INLINES
153 extern __inline int
154 tolower (int __c) __THROW
156 return __c >= -128 && __c < 256 ? __ctype_tolower[__c] : __c;
159 extern __inline int
160 toupper (int __c) __THROW
162 return __c >= -128 && __c < 256 ? __ctype_toupper[__c] : __c;
164 #endif
166 #if __GNUC__ >= 2 && defined __OPTIMIZE__
167 # define __tobody(c, f, a) \
168 ({ int __res; \
169 if (sizeof (c) > 1) \
171 if (__builtin_constant_p (c)) \
173 int __c = (c); \
174 __res = __c < -128 || __c > 255 ? __c : a[__c]; \
176 else \
177 __res = f (c); \
179 else \
180 __res = a[(int) (c)]; \
181 __res; })
183 # define tolower(c) __tobody (c, tolower, __ctype_tolower)
184 # define toupper(c) __tobody (c, toupper, __ctype_toupper)
185 #endif /* Optimizing gcc */
187 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
188 # define isascii(c) __isascii (c)
189 # define toascii(c) __toascii (c)
191 # define _tolower(c) ((int) __ctype_tolower[(int) (c)])
192 # define _toupper(c) ((int) __ctype_toupper[(int) (c)])
193 #endif
195 #endif /* Not __NO_CTYPE. */
198 #ifdef __USE_GNU
199 /* The concept of one static locale per category is not very well
200 thought out. Many applications will need to process its data using
201 information from several different locales. Another application is
202 the implementation of the internationalization handling in the
203 upcoming ISO C++ standard library. To support this another set of
204 the functions using locale data exist which have an additional
205 argument.
207 Attention: all these functions are *not* standardized in any form.
208 This is a proof-of-concept implementation. */
210 /* Structure for reentrant locale using functions. This is an
211 (almost) opaque type for the user level programs. */
212 # include <xlocale.h>
214 /* These definitions are similar to the ones above but all functions
215 take as an argument a handle for the locale which shall be used. */
216 # define __isctype_l(c, type, locale) \
217 ((locale)->__ctype_b[(int) (c)] & (unsigned short int) type)
219 # define __tolower_l(c, locale) ((int) (locale)->__ctype_tolower[(int) (c)])
220 # define __toupper_l(c, locale) ((int) (locale)->__ctype_toupper[(int) (c)])
222 # define __exctype_l(name) extern int name __P ((int, __locale_t))
224 /* The following names are all functions:
225 int isCHARACTERISTIC(int c, locale_t *locale);
226 which return nonzero iff C has CHARACTERISTIC.
227 For the meaning of the characteristic names, see the `enum' above. */
228 __exctype_l (__isalnum_l);
229 __exctype_l (__isalpha_l);
230 __exctype_l (__iscntrl_l);
231 __exctype_l (__isdigit_l);
232 __exctype_l (__islower_l);
233 __exctype_l (__isgraph_l);
234 __exctype_l (__isprint_l);
235 __exctype_l (__ispunct_l);
236 __exctype_l (__isspace_l);
237 __exctype_l (__isupper_l);
238 __exctype_l (__isxdigit_l);
240 __exctype_l (__isblank_l);
243 /* Return the lowercase version of C in locale L. */
244 extern int __tolower_l __P ((int __c, __locale_t __l));
246 /* Return the uppercase version of C. */
247 extern int __toupper_l __P ((int __c, __locale_t __l));
250 # ifndef __NO_CTYPE
251 # define __isalnum_l(c,l) __isctype_l((c), _ISalnum, (l))
252 # define __isalpha_l(c,l) __isctype_l((c), _ISalpha, (l))
253 # define __iscntrl_l(c,l) __isctype_l((c), _IScntrl, (l))
254 # define __isdigit_l(c,l) __isctype_l((c), _ISdigit, (l))
255 # define __islower_l(c,l) __isctype_l((c), _ISlower, (l))
256 # define __isgraph_l(c,l) __isctype_l((c), _ISgraph, (l))
257 # define __isprint_l(c,l) __isctype_l((c), _ISprint, (l))
258 # define __ispunct_l(c,l) __isctype_l((c), _ISpunct, (l))
259 # define __isspace_l(c,l) __isctype_l((c), _ISspace, (l))
260 # define __isupper_l(c,l) __isctype_l((c), _ISupper, (l))
261 # define __isxdigit_l(c,l) __isctype_l((c), _ISxdigit, (l))
263 # define __isblank_l(c,l) __isctype_l((c), _ISblank, (l))
265 # if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
266 # define __isascii_l(c,l) __isascii(c)
267 # define __toascii_l(c,l) __toascii(c)
268 # endif
270 # endif /* Not __NO_CTYPE. */
272 #endif /* Use GNU. */
274 __END_DECLS
276 #endif /* ctype.h */