]> git.ipfire.org Git - thirdparty/glibc.git/blame - ctype/ctype.h
.
[thirdparty/glibc.git] / ctype / ctype.h
CommitLineData
f377d022 1/* Copyright (C) 1991,92,93,95,96,97,98,99,2001,2002,2004
1ab62b32 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
48enum
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. */
cf684340
RM
81extern __const unsigned short int **__ctype_b_loc (void)
82 __attribute__ ((__const));
83extern __const __int32_t **__ctype_tolower_loc (void)
84 __attribute__ ((__const));
85extern __const __int32_t **__ctype_toupper_loc (void)
86 __attribute__ ((__const));
d20fec5d
UD
87
88#define __isctype(c, type) \
cf684340 89 ((*__ctype_b_loc ())[(int) (c)] & (unsigned short int) type)
d20fec5d 90
2303f5fd
UD
91#define __isascii(c) (((c) & ~0x7f) == 0) /* If C is a 7 bit value. */
92#define __toascii(c) ((c) & 0x7f) /* Mask off high bits. */
28f540f4 93
c1422e5b 94#define __exctype(name) extern int name (int) __THROW
28f540f4 95
7a5affeb 96__BEGIN_NAMESPACE_STD
0f283ffc 97
28f540f4
RM
98/* The following names are all functions:
99 int isCHARACTERISTIC(int c);
100 which return nonzero iff C has CHARACTERISTIC.
101 For the meaning of the characteristic names, see the `enum' above. */
102__exctype (isalnum);
103__exctype (isalpha);
104__exctype (iscntrl);
105__exctype (isdigit);
106__exctype (islower);
107__exctype (isgraph);
108__exctype (isprint);
109__exctype (ispunct);
110__exctype (isspace);
111__exctype (isupper);
112__exctype (isxdigit);
113
28f540f4
RM
114
115/* Return the lowercase version of C. */
c1422e5b 116extern int tolower (int __c) __THROW;
28f540f4
RM
117
118/* Return the uppercase version of C. */
c1422e5b 119extern int toupper (int __c) __THROW;
28f540f4 120
7a5affeb
UD
121__END_NAMESPACE_STD
122
123
124/* ISO C99 introduced one new function. */
125#ifdef __USE_ISOC99
126__BEGIN_NAMESPACE_C99
127
128__exctype (isblank);
129
130__END_NAMESPACE_C99
131#endif
28f540f4 132
fa1861d9
UD
133#ifdef __USE_GNU
134/* Test C for a set of character classes according to MASK. */
135extern int isctype (int __c, int __mask) __THROW;
136#endif
137
dfd2257a 138#if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
28f540f4
RM
139
140/* Return nonzero iff C is in the ASCII set
141 (i.e., is no more than 7 bits wide). */
c1422e5b 142extern int isascii (int __c) __THROW;
28f540f4
RM
143
144/* Return the part of C that is in the ASCII set
145 (i.e., the low-order 7 bits of C). */
c1422e5b 146extern int toascii (int __c) __THROW;
28f540f4 147
8d8c6efa
UD
148/* These are the same as `toupper' and `tolower' except that they do not
149 check the argument for being in the range of a `char'. */
28f540f4
RM
150__exctype (_toupper);
151__exctype (_tolower);
70b2845f 152#endif /* Use SVID or use misc. */
28f540f4 153
c1422e5b
UD
154/* This code is needed for the optimized mapping functions. */
155#define __tobody(c, f, a, args) \
156 (__extension__ \
157 ({ int __res; \
158 if (sizeof (c) > 1) \
159 { \
160 if (__builtin_constant_p (c)) \
161 { \
162 int __c = (c); \
0f283ffc 163 __res = __c < -128 || __c > 255 ? __c : (a)[__c]; \
c1422e5b
UD
164 } \
165 else \
166 __res = f args; \
167 } \
168 else \
0f283ffc 169 __res = (a)[(int) (c)]; \
c1422e5b
UD
170 __res; }))
171
7a5affeb 172#if !defined __NO_CTYPE && !defined __cplusplus
d20fec5d
UD
173# define isalnum(c) __isctype((c), _ISalnum)
174# define isalpha(c) __isctype((c), _ISalpha)
175# define iscntrl(c) __isctype((c), _IScntrl)
176# define isdigit(c) __isctype((c), _ISdigit)
177# define islower(c) __isctype((c), _ISlower)
178# define isgraph(c) __isctype((c), _ISgraph)
179# define isprint(c) __isctype((c), _ISprint)
180# define ispunct(c) __isctype((c), _ISpunct)
181# define isspace(c) __isctype((c), _ISspace)
182# define isupper(c) __isctype((c), _ISupper)
183# define isxdigit(c) __isctype((c), _ISxdigit)
184
185# ifdef __USE_ISOC99
186# define isblank(c) __isctype((c), _ISblank)
187# endif
188
189# ifdef __USE_EXTERN_INLINES
190extern __inline int
f377d022 191__NTH (tolower (int __c))
d20fec5d 192{
cf684340 193 return __c >= -128 && __c < 256 ? (*__ctype_tolower_loc ())[__c] : __c;
d20fec5d
UD
194}
195
196extern __inline int
f377d022 197__NTH (toupper (int __c))
d20fec5d 198{
cf684340 199 return __c >= -128 && __c < 256 ? (*__ctype_toupper_loc ())[__c] : __c;
d20fec5d
UD
200}
201# endif
202
203# if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
cf684340
RM
204# define tolower(c) __tobody (c, tolower, *__ctype_tolower_loc (), (c))
205# define toupper(c) __tobody (c, toupper, *__ctype_toupper_loc (), (c))
d20fec5d
UD
206# endif /* Optimizing gcc */
207
c813f986
UD
208# if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
209# define isascii(c) __isascii (c)
210# define toascii(c) __toascii (c)
d20fec5d 211
cf684340
RM
212# define _tolower(c) ((int) (*__ctype_tolower_loc ())[(int) (c)])
213# define _toupper(c) ((int) (*__ctype_toupper_loc ())[(int) (c)])
c813f986 214# endif
d20fec5d 215
28f540f4
RM
216#endif /* Not __NO_CTYPE. */
217
c84142e8
UD
218
219#ifdef __USE_GNU
220/* The concept of one static locale per category is not very well
221 thought out. Many applications will need to process its data using
222 information from several different locales. Another application is
223 the implementation of the internationalization handling in the
224 upcoming ISO C++ standard library. To support this another set of
225 the functions using locale data exist which have an additional
226 argument.
227
228 Attention: all these functions are *not* standardized in any form.
229 This is a proof-of-concept implementation. */
230
231/* Structure for reentrant locale using functions. This is an
232 (almost) opaque type for the user level programs. */
233# include <xlocale.h>
234
235/* These definitions are similar to the ones above but all functions
236 take as an argument a handle for the locale which shall be used. */
c1422e5b 237# define __isctype_l(c, type, locale) \
c84142e8
UD
238 ((locale)->__ctype_b[(int) (c)] & (unsigned short int) type)
239
1ab62b32 240# define __exctype_l(name) \
da4cfe38 241 extern int name (int, __locale_t) __THROW
c84142e8
UD
242
243/* The following names are all functions:
244 int isCHARACTERISTIC(int c, locale_t *locale);
245 which return nonzero iff C has CHARACTERISTIC.
246 For the meaning of the characteristic names, see the `enum' above. */
1ab62b32
RM
247__exctype_l (isalnum_l);
248__exctype_l (isalpha_l);
249__exctype_l (iscntrl_l);
250__exctype_l (isdigit_l);
251__exctype_l (islower_l);
252__exctype_l (isgraph_l);
253__exctype_l (isprint_l);
254__exctype_l (ispunct_l);
255__exctype_l (isspace_l);
256__exctype_l (isupper_l);
257__exctype_l (isxdigit_l);
c84142e8 258
1ab62b32 259__exctype_l (isblank_l);
c84142e8
UD
260
261
262/* Return the lowercase version of C in locale L. */
c1422e5b 263extern int __tolower_l (int __c, __locale_t __l) __THROW;
1ab62b32 264extern int tolower_l (int __c, __locale_t __l) __THROW;
c84142e8
UD
265
266/* Return the uppercase version of C. */
c1422e5b 267extern int __toupper_l (int __c, __locale_t __l) __THROW;
1ab62b32 268extern int toupper_l (int __c, __locale_t __l) __THROW;
c1422e5b
UD
269
270# if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
271# define __tolower_l(c, locale) \
272 __tobody (c, __tolower_l, (locale)->__ctype_tolower, (c, locale))
273# define __toupper_l(c, locale) \
274 __tobody (c, __toupper_l, (locale)->__ctype_toupper, (c, locale))
1ab62b32
RM
275# define tolower_l(c, locale) __tolower_l ((c), (locale))
276# define toupper_l(c, locale) __toupper_l ((c), (locale))
c1422e5b 277# endif /* Optimizing gcc */
c84142e8
UD
278
279
dfd2257a
UD
280# ifndef __NO_CTYPE
281# define __isalnum_l(c,l) __isctype_l((c), _ISalnum, (l))
282# define __isalpha_l(c,l) __isctype_l((c), _ISalpha, (l))
283# define __iscntrl_l(c,l) __isctype_l((c), _IScntrl, (l))
284# define __isdigit_l(c,l) __isctype_l((c), _ISdigit, (l))
285# define __islower_l(c,l) __isctype_l((c), _ISlower, (l))
286# define __isgraph_l(c,l) __isctype_l((c), _ISgraph, (l))
287# define __isprint_l(c,l) __isctype_l((c), _ISprint, (l))
288# define __ispunct_l(c,l) __isctype_l((c), _ISpunct, (l))
289# define __isspace_l(c,l) __isctype_l((c), _ISspace, (l))
290# define __isupper_l(c,l) __isctype_l((c), _ISupper, (l))
291# define __isxdigit_l(c,l) __isctype_l((c), _ISxdigit, (l))
c84142e8 292
dfd2257a
UD
293# define __isblank_l(c,l) __isctype_l((c), _ISblank, (l))
294
295# if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
1ab62b32
RM
296# define __isascii_l(c,l) ((l), __isascii (c))
297# define __toascii_l(c,l) ((l), __toascii (c))
298# endif
299
300# define isalnum_l(c,l) __isalnum_l ((c), (l))
301# define isalpha_l(c,l) __isalpha_l ((c), (l))
302# define iscntrl_l(c,l) __iscntrl_l ((c), (l))
303# define isdigit_l(c,l) __isdigit_l ((c), (l))
304# define islower_l(c,l) __islower_l ((c), (l))
305# define isgraph_l(c,l) __isgraph_l ((c), (l))
306# define isprint_l(c,l) __isprint_l ((c), (l))
307# define ispunct_l(c,l) __ispunct_l ((c), (l))
308# define isspace_l(c,l) __isspace_l ((c), (l))
309# define isupper_l(c,l) __isupper_l ((c), (l))
310# define isxdigit_l(c,l) __isxdigit_l ((c), (l))
311
312# define isblank_l(c,l) __isblank_l ((c), (l))
313
314# if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN
da4cfe38
RM
315# define isascii_l(c,l) __isascii_l ((c), (l))
316# define toascii_l(c,l) __toascii_l ((c), (l))
dfd2257a
UD
317# endif
318
319# endif /* Not __NO_CTYPE. */
c84142e8
UD
320
321#endif /* Use GNU. */
322
28f540f4
RM
323__END_DECLS
324
325#endif /* ctype.h */