1 /* Copyright (C) 1991, 92, 93, 95, 96, 97 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>
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.
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. */
40 #if __BYTE_ORDER == __BIG_ENDIAN
41 #define _ISbit(bit) (1 << bit)
42 #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
43 #define _ISbit(bit) (bit < 8 ? ((1 << bit) << 8) : ((1 << bit) >> 8))
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. */
59 _ISalnum
= _ISbit (11) /* Alphanumeric. */
63 /* These are defined in ctype-info.c.
64 The declarations here must match those in localeinfo.h.
66 These point into arrays of 384, so they can be indexed by any `unsigned
67 char' value [0,255]; by EOF (-1); or by any `signed char' value
68 [-128,-1). ISO C requires that the ctype functions work for `unsigned
69 char' values and for EOF; we also support negative `signed char' values
70 for broken old programs. The case conversion arrays are of `int's
71 rather than `unsigned char's because tolower (EOF) must be EOF, which
72 doesn't fit into an `unsigned char'. But today more important is that
73 the arrays are also used for multi-byte character sets. */
74 extern __const
unsigned short int *__ctype_b
; /* Characteristics. */
75 extern __const
int *__ctype_tolower
; /* Case conversions. */
76 extern __const
int *__ctype_toupper
; /* Case conversions. */
78 #define __isctype(c, type) \
79 (__ctype_b[(int) (c)] & (unsigned short int) type)
81 #define __isascii(c) (((c) & ~0x7f) == 0) /* If C is a 7 bit value. */
82 #define __toascii(c) ((c) & 0x7f) /* Mask off high bits. */
84 #define __tolower(c) ((int) __ctype_tolower[(int) (c)])
85 #define __toupper(c) ((int) __ctype_toupper[(int) (c)])
87 #define __exctype(name) extern int name __P ((int))
89 /* The following names are all functions:
90 int isCHARACTERISTIC(int c);
91 which return nonzero iff C has CHARACTERISTIC.
92 For the meaning of the characteristic names, see the `enum' above. */
103 __exctype (isxdigit
);
110 /* Return the lowercase version of C. */
111 extern int tolower
__P ((int __c
));
113 /* Return the uppercase version of C. */
114 extern int toupper
__P ((int __c
));
117 #if defined(__USE_SVID) || defined(__USE_MISC) || defined(__USE_XOPEN)
119 /* Return nonzero iff C is in the ASCII set
120 (i.e., is no more than 7 bits wide). */
121 extern int isascii
__P ((int __c
));
123 /* Return the part of C that is in the ASCII set
124 (i.e., the low-order 7 bits of C). */
125 extern int toascii
__P ((int __c
));
127 #endif /* Use SVID or use misc. */
129 #if defined(__USE_SVID) || defined(__USE_MISC) || defined(__USE_XOPEN)
130 /* These are the same as `toupper' and `tolower'. */
131 __exctype (_toupper
);
132 __exctype (_tolower
);
136 #define isalnum(c) __isctype((c), _ISalnum)
137 #define isalpha(c) __isctype((c), _ISalpha)
138 #define iscntrl(c) __isctype((c), _IScntrl)
139 #define isdigit(c) __isctype((c), _ISdigit)
140 #define islower(c) __isctype((c), _ISlower)
141 #define isgraph(c) __isctype((c), _ISgraph)
142 #define isprint(c) __isctype((c), _ISprint)
143 #define ispunct(c) __isctype((c), _ISpunct)
144 #define isspace(c) __isctype((c), _ISspace)
145 #define isupper(c) __isctype((c), _ISupper)
146 #define isxdigit(c) __isctype((c), _ISxdigit)
149 #define isblank(c) __isctype((c), _ISblank)
152 #define tolower(c) __tolower(c)
153 #define toupper(c) __toupper(c)
155 #if defined(__USE_SVID) || defined(__USE_MISC) || defined(__USE_XOPEN)
156 #define isascii(c) __isascii(c)
157 #define toascii(c) __toascii(c)
160 #endif /* Not __NO_CTYPE. */
164 /* The concept of one static locale per category is not very well
165 thought out. Many applications will need to process its data using
166 information from several different locales. Another application is
167 the implementation of the internationalization handling in the
168 upcoming ISO C++ standard library. To support this another set of
169 the functions using locale data exist which have an additional
172 Attention: all these functions are *not* standardized in any form.
173 This is a proof-of-concept implementation. */
175 /* Structure for reentrant locale using functions. This is an
176 (almost) opaque type for the user level programs. */
177 # include <xlocale.h>
179 /* These definitions are similar to the ones above but all functions
180 take as an argument a handle for the locale which shall be used. */
181 #define __isctype_l(c, type, locale) \
182 ((locale)->__ctype_b[(int) (c)] & (unsigned short int) type)
184 #define __tolower_l(c, locale) ((int) (locale)->__ctype_tolower[(int) (c)])
185 #define __toupper_l(c, locale) ((int) (locale)->__ctype_toupper[(int) (c)])
187 #define __exctype_l(name) extern int name __P ((int, __locale_t))
189 /* The following names are all functions:
190 int isCHARACTERISTIC(int c, locale_t *locale);
191 which return nonzero iff C has CHARACTERISTIC.
192 For the meaning of the characteristic names, see the `enum' above. */
193 __exctype_l (__isalnum_l
);
194 __exctype_l (__isalpha_l
);
195 __exctype_l (__iscntrl_l
);
196 __exctype_l (__isdigit_l
);
197 __exctype_l (__islower_l
);
198 __exctype_l (__isgraph_l
);
199 __exctype_l (__isprint_l
);
200 __exctype_l (__ispunct_l
);
201 __exctype_l (__isspace_l
);
202 __exctype_l (__isupper_l
);
203 __exctype_l (__isxdigit_l
);
205 __exctype_l (__isblank_l
);
208 /* Return the lowercase version of C in locale L. */
209 extern int __tolower_l
__P ((int __c
, __locale_t __l
));
211 /* Return the uppercase version of C. */
212 extern int __toupper_l
__P ((int __c
, __locale_t __l
));
216 #define __isalnum_l(c,l) __isctype_l((c), _ISalnum, (l))
217 #define __isalpha_l(c,l) __isctype_l((c), _ISalpha, (l))
218 #define __iscntrl_l(c,l) __isctype_l((c), _IScntrl, (l))
219 #define __isdigit_l(c,l) __isctype_l((c), _ISdigit, (l))
220 #define __islower_l(c,l) __isctype_l((c), _ISlower, (l))
221 #define __isgraph_l(c,l) __isctype_l((c), _ISgraph, (l))
222 #define __isprint_l(c,l) __isctype_l((c), _ISprint, (l))
223 #define __ispunct_l(c,l) __isctype_l((c), _ISpunct, (l))
224 #define __isspace_l(c,l) __isctype_l((c), _ISspace, (l))
225 #define __isupper_l(c,l) __isctype_l((c), _ISupper, (l))
226 #define __isxdigit_l(c,l) __isctype_l((c), _ISxdigit, (l))
228 #define __isblank_l(c,l) __isctype_l((c), _ISblank, (l))
230 #if defined(__USE_SVID) || defined(__USE_MISC) || defined(__USE_XOPEN)
231 #define __isascii_l(c,l) __isascii(c)
232 #define __toascii_l(c,l) __toascii(c)
235 #endif /* Not __NO_CTYPE. */
237 #endif /* Use GNU. */