]> git.ipfire.org Git - thirdparty/glibc.git/blob - ctype/ctype.h
* sysdeps/generic/libc-tls.c (__pthread_initialize_minimal): Pass
[thirdparty/glibc.git] / ctype / ctype.h
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.
4
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.
9
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.
14
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. */
19
20 /*
21 * ISO C99 Standard 7.4: Character handling <ctype.h>
22 */
23
24 #ifndef _CTYPE_H
25 #define _CTYPE_H 1
26
27 #include <features.h>
28 #include <bits/types.h>
29
30 __BEGIN_DECLS
31
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.
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
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
47
48 enum
49 {
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. */
62 };
63 #endif /* ! _ISbit */
64
65 #define __isascii(c) (((c) & ~0x7f) == 0) /* If C is a 7 bit value. */
66 #define __toascii(c) ((c) & 0x7f) /* Mask off high bits. */
67
68 #define __exctype(name) extern int name (int) __THROW
69
70 __BEGIN_NAMESPACE_STD
71
72 /* The following names are all functions:
73 int isCHARACTERISTIC(int c);
74 which return nonzero iff C has CHARACTERISTIC.
75 For the meaning of the characteristic names, see the `enum' above. */
76 __exctype (isalnum);
77 __exctype (isalpha);
78 __exctype (iscntrl);
79 __exctype (isdigit);
80 __exctype (islower);
81 __exctype (isgraph);
82 __exctype (isprint);
83 __exctype (ispunct);
84 __exctype (isspace);
85 __exctype (isupper);
86 __exctype (isxdigit);
87
88
89 /* Return the lowercase version of C. */
90 extern int tolower (int __c) __THROW;
91
92 /* Return the uppercase version of C. */
93 extern int toupper (int __c) __THROW;
94
95 __END_NAMESPACE_STD
96
97
98 /* ISO C99 introduced one new function. */
99 #ifdef __USE_ISOC99
100 __BEGIN_NAMESPACE_C99
101
102 __exctype (isblank);
103
104 __END_NAMESPACE_C99
105 #endif
106
107 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
108
109 /* Return nonzero iff C is in the ASCII set
110 (i.e., is no more than 7 bits wide). */
111 extern int isascii (int __c) __THROW;
112
113 /* Return the part of C that is in the ASCII set
114 (i.e., the low-order 7 bits of C). */
115 extern int toascii (int __c) __THROW;
116
117 /* These are the same as `toupper' and `tolower' except that they do not
118 check the argument for being in the range of a `char'. */
119 __exctype (_toupper);
120 __exctype (_tolower);
121 #endif /* Use SVID or use misc. */
122
123 /* This code is needed for the optimized mapping functions. */
124 #define __tobody(c, f, a, args) \
125 (__extension__ \
126 ({ int __res; \
127 if (sizeof (c) > 1) \
128 { \
129 if (__builtin_constant_p (c)) \
130 { \
131 int __c = (c); \
132 __res = __c < -128 || __c > 255 ? __c : (a)[__c]; \
133 } \
134 else \
135 __res = f args; \
136 } \
137 else \
138 __res = (a)[(int) (c)]; \
139 __res; }))
140
141 #if !defined __NO_CTYPE && !defined __cplusplus
142 # if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
143 # define isascii(c) __isascii (c)
144 # define toascii(c) __toascii (c)
145 # endif
146 #endif /* Not __NO_CTYPE. */
147
148
149 #ifdef __USE_GNU
150 /* The concept of one static locale per category is not very well
151 thought out. Many applications will need to process its data using
152 information from several different locales. Another application is
153 the implementation of the internationalization handling in the
154 upcoming ISO C++ standard library. To support this another set of
155 the functions using locale data exist which have an additional
156 argument.
157
158 Attention: all these functions are *not* standardized in any form.
159 This is a proof-of-concept implementation. */
160
161 /* Structure for reentrant locale using functions. This is an
162 (almost) opaque type for the user level programs. */
163 # include <xlocale.h>
164
165 /* These definitions are similar to the ones above but all functions
166 take as an argument a handle for the locale which shall be used. */
167 # define __isctype_l(c, type, locale) \
168 ((locale)->__ctype_b[(int) (c)] & (unsigned short int) type)
169
170 # define __exctype_l(name) \
171 extern int name (int, __locale_t) __THROW
172
173 /* The following names are all functions:
174 int isCHARACTERISTIC(int c, locale_t *locale);
175 which return nonzero iff C has CHARACTERISTIC.
176 For the meaning of the characteristic names, see the `enum' above. */
177 __exctype_l (isalnum_l);
178 __exctype_l (isalpha_l);
179 __exctype_l (iscntrl_l);
180 __exctype_l (isdigit_l);
181 __exctype_l (islower_l);
182 __exctype_l (isgraph_l);
183 __exctype_l (isprint_l);
184 __exctype_l (ispunct_l);
185 __exctype_l (isspace_l);
186 __exctype_l (isupper_l);
187 __exctype_l (isxdigit_l);
188
189 __exctype_l (isblank_l);
190
191
192 /* Return the lowercase version of C in locale L. */
193 extern int __tolower_l (int __c, __locale_t __l) __THROW;
194 extern int tolower_l (int __c, __locale_t __l) __THROW;
195
196 /* Return the uppercase version of C. */
197 extern int __toupper_l (int __c, __locale_t __l) __THROW;
198 extern int toupper_l (int __c, __locale_t __l) __THROW;
199
200 # if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
201 # define __tolower_l(c, locale) \
202 __tobody (c, __tolower_l, (locale)->__ctype_tolower, (c, locale))
203 # define __toupper_l(c, locale) \
204 __tobody (c, __toupper_l, (locale)->__ctype_toupper, (c, locale))
205 # define tolower_l(c, locale) __tolower_l ((c), (locale))
206 # define toupper_l(c, locale) __toupper_l ((c), (locale))
207 # endif /* Optimizing gcc */
208
209
210 # ifndef __NO_CTYPE
211 # define __isalnum_l(c,l) __isctype_l((c), _ISalnum, (l))
212 # define __isalpha_l(c,l) __isctype_l((c), _ISalpha, (l))
213 # define __iscntrl_l(c,l) __isctype_l((c), _IScntrl, (l))
214 # define __isdigit_l(c,l) __isctype_l((c), _ISdigit, (l))
215 # define __islower_l(c,l) __isctype_l((c), _ISlower, (l))
216 # define __isgraph_l(c,l) __isctype_l((c), _ISgraph, (l))
217 # define __isprint_l(c,l) __isctype_l((c), _ISprint, (l))
218 # define __ispunct_l(c,l) __isctype_l((c), _ISpunct, (l))
219 # define __isspace_l(c,l) __isctype_l((c), _ISspace, (l))
220 # define __isupper_l(c,l) __isctype_l((c), _ISupper, (l))
221 # define __isxdigit_l(c,l) __isctype_l((c), _ISxdigit, (l))
222
223 # define __isblank_l(c,l) __isctype_l((c), _ISblank, (l))
224
225 # if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
226 # define __isascii_l(c,l) ((l), __isascii (c))
227 # define __toascii_l(c,l) ((l), __toascii (c))
228 # endif
229
230 # define isalnum_l(c,l) __isalnum_l ((c), (l))
231 # define isalpha_l(c,l) __isalpha_l ((c), (l))
232 # define iscntrl_l(c,l) __iscntrl_l ((c), (l))
233 # define isdigit_l(c,l) __isdigit_l ((c), (l))
234 # define islower_l(c,l) __islower_l ((c), (l))
235 # define isgraph_l(c,l) __isgraph_l ((c), (l))
236 # define isprint_l(c,l) __isprint_l ((c), (l))
237 # define ispunct_l(c,l) __ispunct_l ((c), (l))
238 # define isspace_l(c,l) __isspace_l ((c), (l))
239 # define isupper_l(c,l) __isupper_l ((c), (l))
240 # define isxdigit_l(c,l) __isxdigit_l ((c), (l))
241
242 # define isblank_l(c,l) __isblank_l ((c), (l))
243
244 # if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
245 # define isascii_l(c,l) __isascii_l ((c), (l))
246 # define toascii_l(c,l) __toascii_l ((c), (l))
247 # endif
248
249 # endif /* Not __NO_CTYPE. */
250
251 #endif /* Use GNU. */
252
253 __END_DECLS
254
255 #endif /* ctype.h */