]> git.saurik.com Git - apple/libc.git/blob - include/ctype.h
136036e1789737130f42aa099ce1ac3dc420d164
[apple/libc.git] / include / ctype.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * Copyright (c) 1989, 1993
25 * The Regents of the University of California. All rights reserved.
26 * (c) UNIX System Laboratories, Inc.
27 * All or some portions of this file are derived from material licensed
28 * to the University of California by American Telephone and Telegraph
29 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
30 * the permission of UNIX System Laboratories, Inc.
31 *
32 * This code is derived from software contributed to Berkeley by
33 * Paul Borman at Krystal Technologies.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Berkeley and its contributors.
47 * 4. Neither the name of the University nor the names of its contributors
48 * may be used to endorse or promote products derived from this software
49 * without specific prior written permission.
50 *
51 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * SUCH DAMAGE.
62 *
63 * @(#)ctype.h 8.4 (Berkeley) 1/21/94
64 */
65
66 #ifndef _CTYPE_H_
67 #define _CTYPE_H_
68
69 #include <runetype.h>
70
71 #define _CTYPE_A 0x00000100L /* Alpha */
72 #define _CTYPE_C 0x00000200L /* Control */
73 #define _CTYPE_D 0x00000400L /* Digit */
74 #define _CTYPE_G 0x00000800L /* Graph */
75 #define _CTYPE_L 0x00001000L /* Lower */
76 #define _CTYPE_P 0x00002000L /* Punct */
77 #define _CTYPE_S 0x00004000L /* Space */
78 #define _CTYPE_U 0x00008000L /* Upper */
79 #define _CTYPE_X 0x00010000L /* X digit */
80 #define _CTYPE_B 0x00020000L /* Blank */
81 #define _CTYPE_R 0x00040000L /* Print */
82 #define _CTYPE_I 0x00080000L /* Ideogram */
83 #define _CTYPE_T 0x00100000L /* Special */
84 #define _CTYPE_Q 0x00200000L /* Phonogram */
85 #define _CTYPE_SW0 0x20000000L /* 0 width character */
86 #define _CTYPE_SW1 0x40000000L /* 1 width character */
87 #define _CTYPE_SW2 0x80000000L /* 2 width character */
88 #define _CTYPE_SW3 0xc0000000L /* 3 width character */
89
90 /*
91 * Backward compatibility
92 */
93 #define _A _CTYPE_A /* Alpha */
94 #define _C _CTYPE_C /* Control */
95 #define _D _CTYPE_D /* Digit */
96 #define _G _CTYPE_G /* Graph */
97 #define _L _CTYPE_L /* Lower */
98 #define _P _CTYPE_P /* Punct */
99 #define _S _CTYPE_S /* Space */
100 #define _U _CTYPE_U /* Upper */
101 #define _X _CTYPE_X /* X digit */
102 #define _B _CTYPE_B /* Blank */
103 #define _R _CTYPE_R /* Print */
104 #define _I _CTYPE_I /* Ideogram */
105 #define _T _CTYPE_T /* Special */
106 #define _Q _CTYPE_Q /* Phonogram */
107 #define _SW0 _CTYPE_SW0 /* 0 width character */
108 #define _SW1 _CTYPE_SW1 /* 1 width character */
109 #define _SW2 _CTYPE_SW2 /* 2 width character */
110 #define _SW3 _CTYPE_SW3 /* 3 width character */
111
112 __BEGIN_DECLS
113 int isalnum(int);
114 int isalpha(int);
115 int iscntrl(int);
116 int isdigit(int);
117 int isgraph(int);
118 int islower(int);
119 int isprint(int);
120 int ispunct(int);
121 int isspace(int);
122 int isupper(int);
123 int isxdigit(int);
124 int tolower(int);
125 int toupper(int);
126
127 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
128 int digittoint(int);
129 int isascii(int);
130 int isblank(int);
131 int ishexnumber(int);
132 int isideogram(int);
133 int isnumber(int);
134 int isphonogram(int);
135 int isrune(int);
136 int isspecial(int);
137 int toascii(int);
138 #endif
139 __END_DECLS
140
141
142 #define isalnum(c) __istype((c), (_CTYPE_A|_CTYPE_D))
143 #define isalpha(c) __istype((c), _CTYPE_A)
144 #define iscntrl(c) __istype((c), _CTYPE_C)
145 #define isdigit(c) __isctype((c), _CTYPE_D) /* ANSI -- locale independent */
146 #define isgraph(c) __istype((c), _CTYPE_G)
147 #define islower(c) __istype((c), _CTYPE_L)
148 #define isprint(c) __istype((c), _CTYPE_R)
149 #define ispunct(c) __istype((c), _CTYPE_P)
150 #define isspace(c) __istype((c), _CTYPE_S)
151 #define isupper(c) __istype((c), _CTYPE_U)
152 #define isxdigit(c) __isctype((c), _CTYPE_X) /* ANSI -- locale independent */
153 #define tolower(c) __tolower(c)
154 #define toupper(c) __toupper(c)
155
156 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
157 #define digittoint(c) __maskrune((c), 0xFF)
158 #define isascii(c) ((c & ~0x7F) == 0)
159 #define isblank(c) __istype((c), _CTYPE_B)
160 #define ishexnumber(c) __istype((c), _CTYPE_X)
161 #define isideogram(c) __istype((c), _CTYPE_I)
162 #define isnumber(c) __istype((c), _CTYPE_D)
163 #define isphonogram(c) __istype((c), _CTYPE_Q)
164 #define isrune(c) __istype((c), 0xFFFFFF00L)
165 #define isspecial(c) __istype((c), _CTYPE_T)
166 #define toascii(c) ((c) & 0x7F)
167 #endif
168
169 /* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */
170 __BEGIN_DECLS
171 unsigned long ___runetype(_BSD_CT_RUNE_T_);
172 _BSD_CT_RUNE_T_ ___tolower(_BSD_CT_RUNE_T_);
173 _BSD_CT_RUNE_T_ ___toupper(_BSD_CT_RUNE_T_);
174 __END_DECLS
175
176 /*
177 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
178 * to generate code for extern versions of all our inline functions.
179 */
180 #ifdef _EXTERNALIZE_CTYPE_INLINES_
181 #define _USE_CTYPE_INLINE_
182 #define static
183 #define __inline
184 #endif
185
186 /*
187 * Use inline functions if we are allowed to and the compiler supports them.
188 */
189 #if !defined(_DONT_USE_CTYPE_INLINE_) && \
190 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
191
192 static __inline int
193 __maskrune(_BSD_CT_RUNE_T_ _c, unsigned long _f)
194 {
195 return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
196 _CurrentRuneLocale->runetype[_c]) & _f;
197 }
198
199 static __inline int
200 __istype(_BSD_CT_RUNE_T_ c, unsigned long f)
201 {
202 return !!(__maskrune(c, f));
203 }
204
205 static __inline _BSD_CT_RUNE_T_
206 __isctype(_BSD_CT_RUNE_T_ _c, unsigned long _f)
207 {
208 return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
209 !!(_DefaultRuneLocale.runetype[_c] & _f);
210 }
211
212 static __inline _BSD_CT_RUNE_T_
213 __toupper(_BSD_CT_RUNE_T_ _c)
214 {
215 return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
216 _CurrentRuneLocale->mapupper[_c];
217 }
218
219 static __inline _BSD_CT_RUNE_T_
220 __tolower(_BSD_CT_RUNE_T_ _c)
221 {
222 return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
223 _CurrentRuneLocale->maplower[_c];
224 }
225
226 #else /* not using inlines */
227
228 __BEGIN_DECLS
229 int __maskrune(_BSD_CT_RUNE_T_, unsigned long);
230 int __istype (_BSD_CT_RUNE_T_, unsigned long);
231 int __isctype(_BSD_CT_RUNE_T_, unsigned long);
232 _BSD_CT_RUNE_T_ __toupper(_BSD_CT_RUNE_T_);
233 _BSD_CT_RUNE_T_ __tolower(_BSD_CT_RUNE_T_);
234 __END_DECLS
235 #endif /* using inlines */
236
237 #endif /* !_CTYPE_H_ */