]>
Commit | Line | Data |
---|---|---|
5b2abdfb | 1 | /* |
34e8f829 | 2 | * Copyright (c) 2000, 2005, 2008 Apple Inc. All rights reserved. |
5b2abdfb A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
734aad71 A |
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 | |
5b2abdfb A |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
734aad71 A |
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. | |
5b2abdfb A |
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 | ||
3d9156a7 A |
66 | //Begin-Libc |
67 | #include "xlocale_private.h" | |
68 | //End-Libc | |
5b2abdfb A |
69 | #ifndef _CTYPE_H_ |
70 | #define _CTYPE_H_ | |
71 | ||
6465356a | 72 | #include <sys/cdefs.h> |
5b2abdfb A |
73 | #include <runetype.h> |
74 | ||
9385eb3d A |
75 | #define _CTYPE_A 0x00000100L /* Alpha */ |
76 | #define _CTYPE_C 0x00000200L /* Control */ | |
77 | #define _CTYPE_D 0x00000400L /* Digit */ | |
78 | #define _CTYPE_G 0x00000800L /* Graph */ | |
79 | #define _CTYPE_L 0x00001000L /* Lower */ | |
80 | #define _CTYPE_P 0x00002000L /* Punct */ | |
81 | #define _CTYPE_S 0x00004000L /* Space */ | |
82 | #define _CTYPE_U 0x00008000L /* Upper */ | |
83 | #define _CTYPE_X 0x00010000L /* X digit */ | |
84 | #define _CTYPE_B 0x00020000L /* Blank */ | |
85 | #define _CTYPE_R 0x00040000L /* Print */ | |
86 | #define _CTYPE_I 0x00080000L /* Ideogram */ | |
87 | #define _CTYPE_T 0x00100000L /* Special */ | |
88 | #define _CTYPE_Q 0x00200000L /* Phonogram */ | |
89 | #define _CTYPE_SW0 0x20000000L /* 0 width character */ | |
90 | #define _CTYPE_SW1 0x40000000L /* 1 width character */ | |
91 | #define _CTYPE_SW2 0x80000000L /* 2 width character */ | |
92 | #define _CTYPE_SW3 0xc0000000L /* 3 width character */ | |
3d9156a7 A |
93 | #define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */ |
94 | #define _CTYPE_SWS 30 /* Bits to shift to get width */ | |
9385eb3d | 95 | |
3d9156a7 | 96 | #ifdef _NONSTD_SOURCE |
9385eb3d A |
97 | /* |
98 | * Backward compatibility | |
99 | */ | |
100 | #define _A _CTYPE_A /* Alpha */ | |
101 | #define _C _CTYPE_C /* Control */ | |
102 | #define _D _CTYPE_D /* Digit */ | |
103 | #define _G _CTYPE_G /* Graph */ | |
104 | #define _L _CTYPE_L /* Lower */ | |
105 | #define _P _CTYPE_P /* Punct */ | |
106 | #define _S _CTYPE_S /* Space */ | |
107 | #define _U _CTYPE_U /* Upper */ | |
108 | #define _X _CTYPE_X /* X digit */ | |
109 | #define _B _CTYPE_B /* Blank */ | |
110 | #define _R _CTYPE_R /* Print */ | |
111 | #define _I _CTYPE_I /* Ideogram */ | |
112 | #define _T _CTYPE_T /* Special */ | |
113 | #define _Q _CTYPE_Q /* Phonogram */ | |
114 | #define _SW0 _CTYPE_SW0 /* 0 width character */ | |
115 | #define _SW1 _CTYPE_SW1 /* 1 width character */ | |
116 | #define _SW2 _CTYPE_SW2 /* 2 width character */ | |
117 | #define _SW3 _CTYPE_SW3 /* 3 width character */ | |
3d9156a7 | 118 | #endif /* _NONSTD_SOURCE */ |
5b2abdfb | 119 | |
6465356a | 120 | //Begin-Libc |
5b2abdfb A |
121 | /* |
122 | * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us | |
224c7076 | 123 | * to generate code for extern versions of all intermediate inline functions. |
5b2abdfb A |
124 | */ |
125 | #ifdef _EXTERNALIZE_CTYPE_INLINES_ | |
126 | #define _USE_CTYPE_INLINE_ | |
6465356a | 127 | #define __DARWIN_CTYPE_inline |
224c7076 | 128 | #else /* !_EXTERNALIZE_CTYPE_INLINES_ */ |
6465356a A |
129 | //End-Libc |
130 | #define __DARWIN_CTYPE_inline __header_inline | |
131 | //Begin-Libc | |
224c7076 | 132 | #endif /* !_EXTERNALIZE_CTYPE_INLINES_ */ |
6465356a | 133 | //End-Libc |
224c7076 | 134 | |
6465356a | 135 | //Begin-Libc |
224c7076 A |
136 | /* |
137 | * _EXTERNALIZE_CTYPE_INLINES_TOP_ is defined in locale/isctype.c to tell us | |
138 | * to generate code for extern versions of all top-level inline functions. | |
139 | */ | |
140 | #ifdef _EXTERNALIZE_CTYPE_INLINES_TOP_ | |
141 | #define _USE_CTYPE_INLINE_ | |
6465356a | 142 | #define __DARWIN_CTYPE_TOP_inline |
224c7076 | 143 | #else /* !_EXTERNALIZE_CTYPE_INLINES_TOP_ */ |
6465356a A |
144 | //End-Libc |
145 | #define __DARWIN_CTYPE_TOP_inline __header_inline | |
146 | //Begin-Libc | |
224c7076 | 147 | #endif /* _EXTERNALIZE_CTYPE_INLINES_TOP_ */ |
6465356a | 148 | //End-Libc |
5b2abdfb A |
149 | |
150 | /* | |
151 | * Use inline functions if we are allowed to and the compiler supports them. | |
152 | */ | |
153 | #if !defined(_DONT_USE_CTYPE_INLINE_) && \ | |
154 | (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus)) | |
155 | ||
224c7076 A |
156 | /* See comments in <machine/_type.h> about __darwin_ct_rune_t. */ |
157 | __BEGIN_DECLS | |
158 | unsigned long ___runetype(__darwin_ct_rune_t); | |
159 | __darwin_ct_rune_t ___tolower(__darwin_ct_rune_t); | |
160 | __darwin_ct_rune_t ___toupper(__darwin_ct_rune_t); | |
161 | __END_DECLS | |
162 | ||
6465356a | 163 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
164 | isascii(int _c) |
165 | { | |
166 | return ((_c & ~0x7F) == 0); | |
167 | } | |
168 | ||
3d9156a7 | 169 | #ifdef USE_ASCII |
6465356a | 170 | __DARWIN_CTYPE_inline int |
3d9156a7 A |
171 | __maskrune(__darwin_ct_rune_t _c, unsigned long _f) |
172 | { | |
34e8f829 | 173 | return _DefaultRuneLocale.__runetype[_c & 0xff] & _f; |
3d9156a7 A |
174 | } |
175 | //Begin-Libc | |
176 | #elif defined(__LIBC__) | |
6465356a | 177 | __DARWIN_CTYPE_inline int |
3d9156a7 | 178 | __maskrune(__darwin_ct_rune_t _c, unsigned long _f) |
5b2abdfb A |
179 | { |
180 | return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) : | |
3d9156a7 | 181 | __current_locale()->__lc_ctype->_CurrentRuneLocale.__runetype[_c]) & _f; |
5b2abdfb | 182 | } |
3d9156a7 A |
183 | //End-Libc |
184 | #else /* !USE_ASCII */ | |
185 | __BEGIN_DECLS | |
186 | int __maskrune(__darwin_ct_rune_t, unsigned long); | |
187 | __END_DECLS | |
188 | #endif /* USE_ASCII */ | |
5b2abdfb | 189 | |
6465356a | 190 | __DARWIN_CTYPE_inline int |
3d9156a7 | 191 | __istype(__darwin_ct_rune_t _c, unsigned long _f) |
5b2abdfb | 192 | { |
3d9156a7 A |
193 | #ifdef USE_ASCII |
194 | return !!(__maskrune(_c, _f)); | |
195 | #else /* USE_ASCII */ | |
224c7076 A |
196 | return (isascii(_c) ? !!(_DefaultRuneLocale.__runetype[_c] & _f) |
197 | : !!__maskrune(_c, _f)); | |
3d9156a7 | 198 | #endif /* USE_ASCII */ |
5b2abdfb A |
199 | } |
200 | ||
6465356a | 201 | __DARWIN_CTYPE_inline __darwin_ct_rune_t |
3d9156a7 | 202 | __isctype(__darwin_ct_rune_t _c, unsigned long _f) |
5b2abdfb | 203 | { |
59e0d9fe | 204 | #ifdef USE_ASCII |
34e8f829 | 205 | return !!(__maskrune(_c, _f)); |
59e0d9fe | 206 | #else /* USE_ASCII */ |
5b2abdfb | 207 | return (_c < 0 || _c >= _CACHED_RUNES) ? 0 : |
3d9156a7 | 208 | !!(_DefaultRuneLocale.__runetype[_c] & _f); |
59e0d9fe | 209 | #endif /* USE_ASCII */ |
5b2abdfb A |
210 | } |
211 | ||
59e0d9fe | 212 | #ifdef USE_ASCII |
6465356a | 213 | __DARWIN_CTYPE_inline __darwin_ct_rune_t |
3d9156a7 A |
214 | __toupper(__darwin_ct_rune_t _c) |
215 | { | |
34e8f829 | 216 | return _DefaultRuneLocale.__mapupper[_c & 0xff]; |
3d9156a7 A |
217 | } |
218 | ||
6465356a | 219 | __DARWIN_CTYPE_inline __darwin_ct_rune_t |
3d9156a7 A |
220 | __tolower(__darwin_ct_rune_t _c) |
221 | { | |
34e8f829 | 222 | return _DefaultRuneLocale.__maplower[_c & 0xff]; |
3d9156a7 A |
223 | } |
224 | //Begin-Libc | |
225 | #elif defined(__LIBC__) | |
226 | /* | |
227 | * We can't do what we do for __toupper_l() (check for ASCII first, then call | |
228 | * ___toupper_l() otherwise) because versions of ___toupper() before Tiger | |
229 | * assume c >= _CACHED_RUNES. So we are stuck making __toupper() a routine | |
230 | * to hide the extended locale details, outside of Libc. | |
231 | */ | |
6465356a | 232 | __DARWIN_CTYPE_inline __darwin_ct_rune_t |
3d9156a7 A |
233 | __toupper(__darwin_ct_rune_t _c) |
234 | { | |
5b2abdfb | 235 | return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) : |
3d9156a7 | 236 | __current_locale()->__lc_ctype->_CurrentRuneLocale.__mapupper[_c]; |
5b2abdfb A |
237 | } |
238 | ||
6465356a | 239 | __DARWIN_CTYPE_inline __darwin_ct_rune_t |
3d9156a7 | 240 | __tolower(__darwin_ct_rune_t _c) |
5b2abdfb A |
241 | { |
242 | return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) : | |
3d9156a7 A |
243 | __current_locale()->__lc_ctype->_CurrentRuneLocale.__maplower[_c]; |
244 | } | |
245 | //End-Libc | |
34e8f829 | 246 | #else /* !USE_ASCII */ |
3d9156a7 A |
247 | __BEGIN_DECLS |
248 | __darwin_ct_rune_t __toupper(__darwin_ct_rune_t); | |
249 | __darwin_ct_rune_t __tolower(__darwin_ct_rune_t); | |
250 | __END_DECLS | |
59e0d9fe | 251 | #endif /* USE_ASCII */ |
3d9156a7 | 252 | |
6465356a | 253 | __DARWIN_CTYPE_inline int |
3d9156a7 A |
254 | __wcwidth(__darwin_ct_rune_t _c) |
255 | { | |
256 | unsigned int _x; | |
257 | ||
258 | if (_c == 0) | |
259 | return (0); | |
260 | _x = (unsigned int)__maskrune(_c, _CTYPE_SWM|_CTYPE_R); | |
261 | if ((_x & _CTYPE_SWM) != 0) | |
262 | return ((_x & _CTYPE_SWM) >> _CTYPE_SWS); | |
263 | return ((_x & _CTYPE_R) != 0 ? 1 : -1); | |
5b2abdfb A |
264 | } |
265 | ||
224c7076 A |
266 | #ifndef _EXTERNALIZE_CTYPE_INLINES_ |
267 | ||
268 | #define _tolower(c) __tolower(c) | |
269 | #define _toupper(c) __toupper(c) | |
270 | ||
6465356a | 271 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
272 | isalnum(int _c) |
273 | { | |
274 | return (__istype(_c, _CTYPE_A|_CTYPE_D)); | |
275 | } | |
276 | ||
6465356a | 277 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
278 | isalpha(int _c) |
279 | { | |
280 | return (__istype(_c, _CTYPE_A)); | |
281 | } | |
282 | ||
6465356a | 283 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
284 | isblank(int _c) |
285 | { | |
286 | return (__istype(_c, _CTYPE_B)); | |
287 | } | |
288 | ||
6465356a | 289 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
290 | iscntrl(int _c) |
291 | { | |
292 | return (__istype(_c, _CTYPE_C)); | |
293 | } | |
294 | ||
295 | /* ANSI -- locale independent */ | |
6465356a | 296 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
297 | isdigit(int _c) |
298 | { | |
299 | return (__isctype(_c, _CTYPE_D)); | |
300 | } | |
301 | ||
6465356a | 302 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
303 | isgraph(int _c) |
304 | { | |
305 | return (__istype(_c, _CTYPE_G)); | |
306 | } | |
307 | ||
6465356a | 308 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
309 | islower(int _c) |
310 | { | |
311 | return (__istype(_c, _CTYPE_L)); | |
312 | } | |
313 | ||
6465356a | 314 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
315 | isprint(int _c) |
316 | { | |
317 | return (__istype(_c, _CTYPE_R)); | |
318 | } | |
319 | ||
6465356a | 320 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
321 | ispunct(int _c) |
322 | { | |
323 | return (__istype(_c, _CTYPE_P)); | |
324 | } | |
325 | ||
6465356a | 326 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
327 | isspace(int _c) |
328 | { | |
329 | return (__istype(_c, _CTYPE_S)); | |
330 | } | |
331 | ||
6465356a | 332 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
333 | isupper(int _c) |
334 | { | |
335 | return (__istype(_c, _CTYPE_U)); | |
336 | } | |
337 | ||
338 | /* ANSI -- locale independent */ | |
6465356a | 339 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
340 | isxdigit(int _c) |
341 | { | |
342 | return (__isctype(_c, _CTYPE_X)); | |
343 | } | |
344 | ||
6465356a | 345 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
346 | toascii(int _c) |
347 | { | |
348 | return (_c & 0x7F); | |
349 | } | |
350 | ||
6465356a | 351 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
352 | tolower(int _c) |
353 | { | |
354 | return (__tolower(_c)); | |
355 | } | |
356 | ||
6465356a | 357 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
358 | toupper(int _c) |
359 | { | |
360 | return (__toupper(_c)); | |
361 | } | |
362 | ||
363 | #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) | |
6465356a | 364 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
365 | digittoint(int _c) |
366 | { | |
367 | return (__maskrune(_c, 0x0F)); | |
368 | } | |
369 | ||
6465356a | 370 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
371 | ishexnumber(int _c) |
372 | { | |
373 | return (__istype(_c, _CTYPE_X)); | |
374 | } | |
375 | ||
6465356a | 376 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
377 | isideogram(int _c) |
378 | { | |
379 | return (__istype(_c, _CTYPE_I)); | |
380 | } | |
381 | ||
6465356a | 382 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
383 | isnumber(int _c) |
384 | { | |
385 | return (__istype(_c, _CTYPE_D)); | |
386 | } | |
387 | ||
6465356a | 388 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
389 | isphonogram(int _c) |
390 | { | |
391 | return (__istype(_c, _CTYPE_Q)); | |
392 | } | |
393 | ||
6465356a | 394 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
395 | isrune(int _c) |
396 | { | |
397 | return (__istype(_c, 0xFFFFFFF0L)); | |
398 | } | |
399 | ||
6465356a | 400 | __DARWIN_CTYPE_TOP_inline int |
224c7076 A |
401 | isspecial(int _c) |
402 | { | |
403 | return (__istype(_c, _CTYPE_T)); | |
404 | } | |
405 | #endif /* !_ANSI_SOURCE && (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ | |
406 | #endif /* _EXTERNALIZE_CTYPE_INLINES_ */ | |
407 | ||
5b2abdfb A |
408 | #else /* not using inlines */ |
409 | ||
410 | __BEGIN_DECLS | |
224c7076 A |
411 | int isalnum(int); |
412 | int isalpha(int); | |
413 | int isblank(int); | |
414 | int iscntrl(int); | |
415 | int isdigit(int); | |
416 | int isgraph(int); | |
417 | int islower(int); | |
418 | int isprint(int); | |
419 | int ispunct(int); | |
420 | int isspace(int); | |
421 | int isupper(int); | |
422 | int isxdigit(int); | |
423 | int tolower(int); | |
424 | int toupper(int); | |
425 | int isascii(int); | |
426 | int toascii(int); | |
427 | ||
428 | #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)) | |
429 | int _tolower(int); | |
430 | int _toupper(int); | |
431 | int digittoint(int); | |
432 | int ishexnumber(int); | |
433 | int isideogram(int); | |
434 | int isnumber(int); | |
435 | int isphonogram(int); | |
436 | int isrune(int); | |
437 | int isspecial(int); | |
438 | #endif | |
5b2abdfb | 439 | __END_DECLS |
224c7076 | 440 | |
5b2abdfb A |
441 | #endif /* using inlines */ |
442 | ||
3d9156a7 A |
443 | #ifdef _USE_EXTENDED_LOCALES_ |
444 | #include <xlocale/_ctype.h> | |
445 | #endif /* _USE_EXTENDED_LOCALES_ */ | |
446 | ||
5b2abdfb | 447 | #endif /* !_CTYPE_H_ */ |