2 * Copyright (c) 2000, 2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
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.
32 * This code is derived from software contributed to Berkeley by
33 * Paul Borman at Krystal Technologies.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
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.
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
63 * @(#)ctype.h 8.4 (Berkeley) 1/21/94
67 #include "xlocale_private.h"
74 #define _CTYPE_A 0x00000100L /* Alpha */
75 #define _CTYPE_C 0x00000200L /* Control */
76 #define _CTYPE_D 0x00000400L /* Digit */
77 #define _CTYPE_G 0x00000800L /* Graph */
78 #define _CTYPE_L 0x00001000L /* Lower */
79 #define _CTYPE_P 0x00002000L /* Punct */
80 #define _CTYPE_S 0x00004000L /* Space */
81 #define _CTYPE_U 0x00008000L /* Upper */
82 #define _CTYPE_X 0x00010000L /* X digit */
83 #define _CTYPE_B 0x00020000L /* Blank */
84 #define _CTYPE_R 0x00040000L /* Print */
85 #define _CTYPE_I 0x00080000L /* Ideogram */
86 #define _CTYPE_T 0x00100000L /* Special */
87 #define _CTYPE_Q 0x00200000L /* Phonogram */
88 #define _CTYPE_SW0 0x20000000L /* 0 width character */
89 #define _CTYPE_SW1 0x40000000L /* 1 width character */
90 #define _CTYPE_SW2 0x80000000L /* 2 width character */
91 #define _CTYPE_SW3 0xc0000000L /* 3 width character */
92 #define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */
93 #define _CTYPE_SWS 30 /* Bits to shift to get width */
97 * Backward compatibility
99 #define _A _CTYPE_A /* Alpha */
100 #define _C _CTYPE_C /* Control */
101 #define _D _CTYPE_D /* Digit */
102 #define _G _CTYPE_G /* Graph */
103 #define _L _CTYPE_L /* Lower */
104 #define _P _CTYPE_P /* Punct */
105 #define _S _CTYPE_S /* Space */
106 #define _U _CTYPE_U /* Upper */
107 #define _X _CTYPE_X /* X digit */
108 #define _B _CTYPE_B /* Blank */
109 #define _R _CTYPE_R /* Print */
110 #define _I _CTYPE_I /* Ideogram */
111 #define _T _CTYPE_T /* Special */
112 #define _Q _CTYPE_Q /* Phonogram */
113 #define _SW0 _CTYPE_SW0 /* 0 width character */
114 #define _SW1 _CTYPE_SW1 /* 1 width character */
115 #define _SW2 _CTYPE_SW2 /* 2 width character */
116 #define _SW3 _CTYPE_SW3 /* 3 width character */
117 #endif /* _NONSTD_SOURCE */
120 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
121 * to generate code for extern versions of all intermediate inline functions.
123 #ifdef _EXTERNALIZE_CTYPE_INLINES_
124 #define _USE_CTYPE_INLINE_
125 #define __DARWIN_CTYPE_static_inline
126 #else /* !_EXTERNALIZE_CTYPE_INLINES_ */
127 #define __DARWIN_CTYPE_static_inline static __inline
128 #endif /* !_EXTERNALIZE_CTYPE_INLINES_ */
131 * _EXTERNALIZE_CTYPE_INLINES_TOP_ is defined in locale/isctype.c to tell us
132 * to generate code for extern versions of all top-level inline functions.
134 #ifdef _EXTERNALIZE_CTYPE_INLINES_TOP_
135 #define _USE_CTYPE_INLINE_
136 #define __DARWIN_CTYPE_TOP_static_inline
137 #else /* !_EXTERNALIZE_CTYPE_INLINES_TOP_ */
138 #define __DARWIN_CTYPE_TOP_static_inline static __inline
139 #endif /* _EXTERNALIZE_CTYPE_INLINES_TOP_ */
142 * Use inline functions if we are allowed to and the compiler supports them.
144 #if !defined(_DONT_USE_CTYPE_INLINE_) && \
145 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
147 /* See comments in <machine/_type.h> about __darwin_ct_rune_t. */
149 unsigned long ___runetype(__darwin_ct_rune_t
);
150 __darwin_ct_rune_t
___tolower(__darwin_ct_rune_t
);
151 __darwin_ct_rune_t
___toupper(__darwin_ct_rune_t
);
154 __DARWIN_CTYPE_TOP_static_inline
int
157 return ((_c
& ~0x7F) == 0);
161 __DARWIN_CTYPE_static_inline
int
162 __maskrune(__darwin_ct_rune_t _c
, unsigned long _f
)
164 return _CurrentRuneLocale
->__runetype
[_c
&& 0xff] & _f
;
167 #elif defined(__LIBC__)
168 __DARWIN_CTYPE_static_inline
int
169 __maskrune(__darwin_ct_rune_t _c
, unsigned long _f
)
171 return ((_c
< 0 || _c
>= _CACHED_RUNES
) ? ___runetype(_c
) :
172 __current_locale()->__lc_ctype
->_CurrentRuneLocale
.__runetype
[_c
]) & _f
;
175 #else /* !USE_ASCII */
177 int __maskrune(__darwin_ct_rune_t
, unsigned long);
179 #endif /* USE_ASCII */
181 __DARWIN_CTYPE_static_inline
int
182 __istype(__darwin_ct_rune_t _c
, unsigned long _f
)
185 return !!(__maskrune(_c
, _f
));
186 #else /* USE_ASCII */
187 return (isascii(_c
) ? !!(_DefaultRuneLocale
.__runetype
[_c
] & _f
)
188 : !!__maskrune(_c
, _f
));
189 #endif /* USE_ASCII */
192 __DARWIN_CTYPE_static_inline __darwin_ct_rune_t
193 __isctype(__darwin_ct_rune_t _c
, unsigned long _f
)
196 return !!(_DefaultRuneLocale
.__runetype
[_c
& 0xff] & _f
);
197 #else /* USE_ASCII */
198 return (_c
< 0 || _c
>= _CACHED_RUNES
) ? 0 :
199 !!(_DefaultRuneLocale
.__runetype
[_c
] & _f
);
200 #endif /* USE_ASCII */
204 __DARWIN_CTYPE_static_inline __darwin_ct_rune_t
205 __toupper(__darwin_ct_rune_t _c
)
207 return _CurrentRuneLocale
->__mapupper
[_c
& 0xff];
210 __DARWIN_CTYPE_static_inline __darwin_ct_rune_t
211 __tolower(__darwin_ct_rune_t _c
)
213 return _CurrentRuneLocale
->__maplower
[_c
& 0xff];
216 #elif defined(__LIBC__)
218 * We can't do what we do for __toupper_l() (check for ASCII first, then call
219 * ___toupper_l() otherwise) because versions of ___toupper() before Tiger
220 * assume c >= _CACHED_RUNES. So we are stuck making __toupper() a routine
221 * to hide the extended locale details, outside of Libc.
223 __DARWIN_CTYPE_static_inline __darwin_ct_rune_t
224 __toupper(__darwin_ct_rune_t _c
)
226 return (_c
< 0 || _c
>= _CACHED_RUNES
) ? ___toupper(_c
) :
227 __current_locale()->__lc_ctype
->_CurrentRuneLocale
.__mapupper
[_c
];
230 __DARWIN_CTYPE_static_inline __darwin_ct_rune_t
231 __tolower(__darwin_ct_rune_t _c
)
233 return (_c
< 0 || _c
>= _CACHED_RUNES
) ? ___tolower(_c
) :
234 __current_locale()->__lc_ctype
->_CurrentRuneLocale
.__maplower
[_c
];
237 #else /* USE_ASCII */
239 __darwin_ct_rune_t
__toupper(__darwin_ct_rune_t
);
240 __darwin_ct_rune_t
__tolower(__darwin_ct_rune_t
);
242 #endif /* USE_ASCII */
244 __DARWIN_CTYPE_static_inline
int
245 __wcwidth(__darwin_ct_rune_t _c
)
251 _x
= (unsigned int)__maskrune(_c
, _CTYPE_SWM
|_CTYPE_R
);
252 if ((_x
& _CTYPE_SWM
) != 0)
253 return ((_x
& _CTYPE_SWM
) >> _CTYPE_SWS
);
254 return ((_x
& _CTYPE_R
) != 0 ? 1 : -1);
257 #ifndef _EXTERNALIZE_CTYPE_INLINES_
259 #define _tolower(c) __tolower(c)
260 #define _toupper(c) __toupper(c)
262 __DARWIN_CTYPE_TOP_static_inline
int
265 return (__istype(_c
, _CTYPE_A
|_CTYPE_D
));
268 __DARWIN_CTYPE_TOP_static_inline
int
271 return (__istype(_c
, _CTYPE_A
));
274 __DARWIN_CTYPE_TOP_static_inline
int
277 return (__istype(_c
, _CTYPE_B
));
280 __DARWIN_CTYPE_TOP_static_inline
int
283 return (__istype(_c
, _CTYPE_C
));
286 /* ANSI -- locale independent */
287 __DARWIN_CTYPE_TOP_static_inline
int
290 return (__isctype(_c
, _CTYPE_D
));
293 __DARWIN_CTYPE_TOP_static_inline
int
296 return (__istype(_c
, _CTYPE_G
));
299 __DARWIN_CTYPE_TOP_static_inline
int
302 return (__istype(_c
, _CTYPE_L
));
305 __DARWIN_CTYPE_TOP_static_inline
int
308 return (__istype(_c
, _CTYPE_R
));
311 __DARWIN_CTYPE_TOP_static_inline
int
314 return (__istype(_c
, _CTYPE_P
));
317 __DARWIN_CTYPE_TOP_static_inline
int
320 return (__istype(_c
, _CTYPE_S
));
323 __DARWIN_CTYPE_TOP_static_inline
int
326 return (__istype(_c
, _CTYPE_U
));
329 /* ANSI -- locale independent */
330 __DARWIN_CTYPE_TOP_static_inline
int
333 return (__isctype(_c
, _CTYPE_X
));
336 __DARWIN_CTYPE_TOP_static_inline
int
342 __DARWIN_CTYPE_TOP_static_inline
int
345 return (__tolower(_c
));
348 __DARWIN_CTYPE_TOP_static_inline
int
351 return (__toupper(_c
));
354 #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
355 __DARWIN_CTYPE_TOP_static_inline
int
358 return (__maskrune(_c
, 0x0F));
361 __DARWIN_CTYPE_TOP_static_inline
int
364 return (__istype(_c
, _CTYPE_X
));
367 __DARWIN_CTYPE_TOP_static_inline
int
370 return (__istype(_c
, _CTYPE_I
));
373 __DARWIN_CTYPE_TOP_static_inline
int
376 return (__istype(_c
, _CTYPE_D
));
379 __DARWIN_CTYPE_TOP_static_inline
int
382 return (__istype(_c
, _CTYPE_Q
));
385 __DARWIN_CTYPE_TOP_static_inline
int
388 return (__istype(_c
, 0xFFFFFFF0L
));
391 __DARWIN_CTYPE_TOP_static_inline
int
394 return (__istype(_c
, _CTYPE_T
));
396 #endif /* !_ANSI_SOURCE && (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */
397 #endif /* _EXTERNALIZE_CTYPE_INLINES_ */
399 #else /* not using inlines */
419 #if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE))
423 int ishexnumber(int);
426 int isphonogram(int);
432 #endif /* using inlines */
434 #ifdef _USE_EXTENDED_LOCALES_
435 #include <xlocale/_ctype.h>
436 #endif /* _USE_EXTENDED_LOCALES_ */
438 #endif /* !_CTYPE_H_ */