]> git.ipfire.org Git - thirdparty/glibc.git/blob - ctype/ctype.h
* locale/categories.def (LC_CTYPE): Merge CLASS_EB and CLASS_EL
[thirdparty/glibc.git] / ctype / ctype.h
1 /* Copyright (C) 1991, 1992, 1993, 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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
16 not, write to the, 1992 Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
18
19 /*
20 * ANSI Standard 4.3: CHARACTER HANDLING <ctype.h>
21 */
22
23 #ifndef _CTYPE_H
24
25 #define _CTYPE_H 1
26 #include <features.h>
27
28 __BEGIN_DECLS
29
30 /* These are all the characteristics of characters.
31 If there get to be more than 16 distinct characteristics,
32 many things must be changed that use `unsigned short int's.
33
34 The characteristics are stored always in network byte order (big
35 endian). We define the bit value interpretations here dependent on the
36 machine's byte order. */
37
38 #include <endian.h>
39 #if __BYTE_ORDER == __BIG_ENDIAN
40 #define _ISbit(bit) (1 << bit)
41 #else /* __BYTE_ORDER == __LITTLE_ENDIAN */
42 #define _ISbit(bit) (bit < 8 ? ((1 << bit) << 8) : ((1 << bit) >> 8))
43 #endif
44
45 enum
46 {
47 _ISupper = _ISbit (0), /* UPPERCASE. */
48 _ISlower = _ISbit (1), /* lowercase. */
49 _ISalpha = _ISbit (2), /* Alphabetic. */
50 _ISdigit = _ISbit (3), /* Numeric. */
51 _ISxdigit = _ISbit (4), /* Hexadecimal numeric. */
52 _ISspace = _ISbit (5), /* Whitespace. */
53 _ISprint = _ISbit (6), /* Printing. */
54 _ISgraph = _ISbit (7), /* Graphical. */
55 _ISblank = _ISbit (8), /* Blank (usually SPC and TAB). */
56 _IScntrl = _ISbit (9), /* Control character. */
57 _ISpunct = _ISbit (10), /* Punctuation. */
58
59 /* The following are defined in POSIX.2 as being combinations of the
60 classes above. */
61 _ISalnum = _ISalpha | _ISdigit /* Alphanumeric. */
62 };
63
64 /* These are defined in ctype-info.c.
65 The declarations here must match those in localeinfo.h.
66
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). ANSI 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'. */
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. */
77
78 #define __isctype(c, type) \
79 (__ctype_b[(int) (c)] & (unsigned short int) type)
80
81 #define __isascii(c) (((c) & (1 << 7)) == 0) /* If high bit is set. */
82 #define __toascii(c) ((c) & 0x7f) /* Mask off high bit. */
83
84 #define __tolower(c) ((int) __ctype_tolower[(int) (c)])
85 #define __toupper(c) ((int) __ctype_toupper[(int) (c)])
86
87 #define __exctype(name) extern int name __P ((int))
88
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. */
93 __exctype (isalnum);
94 __exctype (isalpha);
95 __exctype (iscntrl);
96 __exctype (isdigit);
97 __exctype (islower);
98 __exctype (isgraph);
99 __exctype (isprint);
100 __exctype (ispunct);
101 __exctype (isspace);
102 __exctype (isupper);
103 __exctype (isxdigit);
104
105 #ifdef __USE_GNU
106 __exctype (isblank);
107 #endif
108
109
110 /* Return the lowercase version of C. */
111 extern int tolower __P ((int __c));
112
113 /* Return the uppercase version of C. */
114 extern int toupper __P ((int __c));
115
116
117 #if defined(__USE_SVID) || defined(__USE_MISC)
118
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));
122
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));
126
127 #endif /* Use SVID or use misc. */
128
129 #ifdef __USE_SVID
130 /* These are the same as `toupper' and `tolower'. */
131 __exctype (_toupper);
132 __exctype (_tolower);
133 #endif
134
135 #ifndef __NO_CTYPE
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)
147
148 #ifdef __USE_GNU
149 #define isblank(c) __isctype((c), _ISblank)
150 #endif
151
152 #define tolower(c) __tolower(c)
153 #define toupper(c) __toupper(c)
154
155 #if defined(__USE_SVID) || defined(__USE_MISC)
156 #define isascii(c) __isascii(c)
157 #define toascii(c) __toascii(c)
158 #endif
159
160 #endif /* Not __NO_CTYPE. */
161
162 __END_DECLS
163
164 #endif /* ctype.h */