]> sourceware.org Git - glibc.git/blame - ctype/ctype.h
Update.
[glibc.git] / ctype / ctype.h
CommitLineData
c84142e8 1/* Copyright (C) 1991, 92, 93, 95, 96, 97 Free Software Foundation, Inc.
ba1ffaa1 2 This file is part of the GNU C Library.
28f540f4 3
ba1ffaa1
UD
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.
28f540f4 8
ba1ffaa1
UD
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.
28f540f4 13
ba1ffaa1
UD
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. */
28f540f4
RM
18
19/*
ba1ffaa1 20 * ISO C Standard 4.3: CHARACTER HANDLING <ctype.h>
28f540f4
RM
21 */
22
23#ifndef _CTYPE_H
28f540f4 24#define _CTYPE_H 1
5107cf1d 25
28f540f4 26#include <features.h>
5107cf1d 27#include <gnu/types.h>
28f540f4
RM
28
29__BEGIN_DECLS
30
19bc17a9 31#ifndef _ISbit
28635115
RM
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.
35
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. */
39
40#include <endian.h>
41#if __BYTE_ORDER == __BIG_ENDIAN
42#define _ISbit(bit) (1 << bit)
43#else /* __BYTE_ORDER == __LITTLE_ENDIAN */
40deae08 44#define _ISbit(bit) (bit < 8 ? ((1 << bit) << 8) : ((1 << bit) >> 8))
28635115
RM
45#endif
46
28f540f4
RM
47enum
48{
28635115
RM
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. */
19bc17a9 60 _ISalnum = _ISbit (11) /* Alphanumeric. */
28f540f4 61};
19bc17a9 62#endif /* ! _ISbit */
28f540f4 63
28635115 64/* These are defined in ctype-info.c.
28f540f4
RM
65 The declarations here must match those in localeinfo.h.
66
28635115
RM
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
ba1ffaa1 69 [-128,-1). ISO C requires that the ctype functions work for `unsigned
28635115 70 char' values and for EOF; we also support negative `signed char' values
6c2f0507 71 for broken old programs. The case conversion arrays are of `int's
28635115 72 rather than `unsigned char's because tolower (EOF) must be EOF, which
19bc17a9
RM
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. */
28f540f4 75extern __const unsigned short int *__ctype_b; /* Characteristics. */
5107cf1d
UD
76extern __const __int32_t *__ctype_tolower; /* Case conversions. */
77extern __const __int32_t *__ctype_toupper; /* Case conversions. */
28f540f4
RM
78
79#define __isctype(c, type) \
80 (__ctype_b[(int) (c)] & (unsigned short int) type)
81
2303f5fd
UD
82#define __isascii(c) (((c) & ~0x7f) == 0) /* If C is a 7 bit value. */
83#define __toascii(c) ((c) & 0x7f) /* Mask off high bits. */
28f540f4
RM
84
85#define __tolower(c) ((int) __ctype_tolower[(int) (c)])
86#define __toupper(c) ((int) __ctype_toupper[(int) (c)])
87
88#define __exctype(name) extern int name __P ((int))
89
90/* The following names are all functions:
91 int isCHARACTERISTIC(int c);
92 which return nonzero iff C has CHARACTERISTIC.
93 For the meaning of the characteristic names, see the `enum' above. */
94__exctype (isalnum);
95__exctype (isalpha);
96__exctype (iscntrl);
97__exctype (isdigit);
98__exctype (islower);
99__exctype (isgraph);
100__exctype (isprint);
101__exctype (ispunct);
102__exctype (isspace);
103__exctype (isupper);
104__exctype (isxdigit);
105
106#ifdef __USE_GNU
107__exctype (isblank);
108#endif
109
110
111/* Return the lowercase version of C. */
112extern int tolower __P ((int __c));
113
114/* Return the uppercase version of C. */
115extern int toupper __P ((int __c));
116
117
2c6fe0bd 118#if defined(__USE_SVID) || defined(__USE_MISC) || defined(__USE_XOPEN)
28f540f4
RM
119
120/* Return nonzero iff C is in the ASCII set
121 (i.e., is no more than 7 bits wide). */
122extern int isascii __P ((int __c));
123
124/* Return the part of C that is in the ASCII set
125 (i.e., the low-order 7 bits of C). */
126extern int toascii __P ((int __c));
127
128#endif /* Use SVID or use misc. */
129
2303f5fd 130#if defined(__USE_SVID) || defined(__USE_MISC) || defined(__USE_XOPEN)
933e73fa 131/* These are the same as `toupper' and `tolower'. */
28f540f4
RM
132__exctype (_toupper);
133__exctype (_tolower);
134#endif
135
136#ifndef __NO_CTYPE
137#define isalnum(c) __isctype((c), _ISalnum)
138#define isalpha(c) __isctype((c), _ISalpha)
139#define iscntrl(c) __isctype((c), _IScntrl)
140#define isdigit(c) __isctype((c), _ISdigit)
141#define islower(c) __isctype((c), _ISlower)
142#define isgraph(c) __isctype((c), _ISgraph)
143#define isprint(c) __isctype((c), _ISprint)
144#define ispunct(c) __isctype((c), _ISpunct)
145#define isspace(c) __isctype((c), _ISspace)
146#define isupper(c) __isctype((c), _ISupper)
147#define isxdigit(c) __isctype((c), _ISxdigit)
148
149#ifdef __USE_GNU
150#define isblank(c) __isctype((c), _ISblank)
151#endif
152
153#define tolower(c) __tolower(c)
154#define toupper(c) __toupper(c)
155
2303f5fd 156#if defined(__USE_SVID) || defined(__USE_MISC) || defined(__USE_XOPEN)
28f540f4
RM
157#define isascii(c) __isascii(c)
158#define toascii(c) __toascii(c)
159#endif
160
161#endif /* Not __NO_CTYPE. */
162
c84142e8
UD
163
164#ifdef __USE_GNU
165/* The concept of one static locale per category is not very well
166 thought out. Many applications will need to process its data using
167 information from several different locales. Another application is
168 the implementation of the internationalization handling in the
169 upcoming ISO C++ standard library. To support this another set of
170 the functions using locale data exist which have an additional
171 argument.
172
173 Attention: all these functions are *not* standardized in any form.
174 This is a proof-of-concept implementation. */
175
176/* Structure for reentrant locale using functions. This is an
177 (almost) opaque type for the user level programs. */
178# include <xlocale.h>
179
180/* These definitions are similar to the ones above but all functions
181 take as an argument a handle for the locale which shall be used. */
182#define __isctype_l(c, type, locale) \
183 ((locale)->__ctype_b[(int) (c)] & (unsigned short int) type)
184
185#define __tolower_l(c, locale) ((int) (locale)->__ctype_tolower[(int) (c)])
186#define __toupper_l(c, locale) ((int) (locale)->__ctype_toupper[(int) (c)])
187
188#define __exctype_l(name) extern int name __P ((int, __locale_t))
189
190/* The following names are all functions:
191 int isCHARACTERISTIC(int c, locale_t *locale);
192 which return nonzero iff C has CHARACTERISTIC.
193 For the meaning of the characteristic names, see the `enum' above. */
194__exctype_l (__isalnum_l);
195__exctype_l (__isalpha_l);
196__exctype_l (__iscntrl_l);
197__exctype_l (__isdigit_l);
198__exctype_l (__islower_l);
199__exctype_l (__isgraph_l);
200__exctype_l (__isprint_l);
201__exctype_l (__ispunct_l);
202__exctype_l (__isspace_l);
203__exctype_l (__isupper_l);
204__exctype_l (__isxdigit_l);
205
206__exctype_l (__isblank_l);
207
208
209/* Return the lowercase version of C in locale L. */
210extern int __tolower_l __P ((int __c, __locale_t __l));
211
212/* Return the uppercase version of C. */
213extern int __toupper_l __P ((int __c, __locale_t __l));
214
215
216#ifndef __NO_CTYPE
217#define __isalnum_l(c,l) __isctype_l((c), _ISalnum, (l))
218#define __isalpha_l(c,l) __isctype_l((c), _ISalpha, (l))
219#define __iscntrl_l(c,l) __isctype_l((c), _IScntrl, (l))
220#define __isdigit_l(c,l) __isctype_l((c), _ISdigit, (l))
221#define __islower_l(c,l) __isctype_l((c), _ISlower, (l))
222#define __isgraph_l(c,l) __isctype_l((c), _ISgraph, (l))
223#define __isprint_l(c,l) __isctype_l((c), _ISprint, (l))
224#define __ispunct_l(c,l) __isctype_l((c), _ISpunct, (l))
225#define __isspace_l(c,l) __isctype_l((c), _ISspace, (l))
226#define __isupper_l(c,l) __isctype_l((c), _ISupper, (l))
227#define __isxdigit_l(c,l) __isctype_l((c), _ISxdigit, (l))
228
229#define __isblank_l(c,l) __isctype_l((c), _ISblank, (l))
230
231#if defined(__USE_SVID) || defined(__USE_MISC) || defined(__USE_XOPEN)
232#define __isascii_l(c,l) __isascii(c)
233#define __toascii_l(c,l) __toascii(c)
234#endif
235
236#endif /* Not __NO_CTYPE. */
237
238#endif /* Use GNU. */
239
28f540f4
RM
240__END_DECLS
241
242#endif /* ctype.h */
This page took 0.075416 seconds and 5 git commands to generate.