]> git.saurik.com Git - apple/libc.git/blob - include/xlocale/_ctype.h
Libc-1439.100.3.tar.gz
[apple/libc.git] / include / xlocale / _ctype.h
1 /*
2 * Copyright (c) 2005 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 #ifndef _XLOCALE__CTYPE_H_
25 #define _XLOCALE__CTYPE_H_
26
27 #include <_ctype.h>
28 #include <_xlocale.h>
29
30 /*
31 * Use inline functions if we are allowed to and the compiler supports them.
32 */
33 #if !defined(_DONT_USE_CTYPE_INLINE_) && \
34 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
35
36 /* See comments in <machine/_type.h> about __darwin_ct_rune_t. */
37 __BEGIN_DECLS
38 unsigned long ___runetype_l(__darwin_ct_rune_t, locale_t);
39 __darwin_ct_rune_t ___tolower_l(__darwin_ct_rune_t, locale_t);
40 __darwin_ct_rune_t ___toupper_l(__darwin_ct_rune_t, locale_t);
41 __END_DECLS
42
43 //Begin-Libc
44 #ifdef __LIBC__
45 __DARWIN_CTYPE_inline int
46 __maskrune_l(__darwin_ct_rune_t _c, unsigned long _f, locale_t _l)
47 {
48 /* _CurrentRuneLocale.__runetype is __uint32_t
49 * _f is unsigned long
50 * ___runetype_l(_c, _l) is unsigned long
51 * retval is int
52 */
53 return (int)((_c < 0 || _c >= _CACHED_RUNES) ? (__uint32_t)___runetype_l(_c, _l) :
54 __locale_ptr(_l)->__lc_ctype->_CurrentRuneLocale.__runetype[_c]) & (__uint32_t)_f;
55 }
56 #else /* !__LIBC__ */
57 //End-Libc
58 __BEGIN_DECLS
59 int __maskrune_l(__darwin_ct_rune_t, unsigned long, locale_t);
60 __END_DECLS
61 //Begin-Libc
62 #endif /* __LIBC__ */
63 //End-Libc
64
65 __DARWIN_CTYPE_inline int
66 __istype_l(__darwin_ct_rune_t _c, unsigned long _f, locale_t _l)
67 {
68 return !!(isascii(_c) ? (_DefaultRuneLocale.__runetype[_c] & _f)
69 : __maskrune_l(_c, _f, _l));
70 }
71
72 __DARWIN_CTYPE_inline __darwin_ct_rune_t
73 __toupper_l(__darwin_ct_rune_t _c, locale_t _l)
74 {
75 return isascii(_c) ? _DefaultRuneLocale.__mapupper[_c]
76 : ___toupper_l(_c, _l);
77 }
78
79 __DARWIN_CTYPE_inline __darwin_ct_rune_t
80 __tolower_l(__darwin_ct_rune_t _c, locale_t _l)
81 {
82 return isascii(_c) ? _DefaultRuneLocale.__maplower[_c]
83 : ___tolower_l(_c, _l);
84 }
85
86 __DARWIN_CTYPE_inline int
87 __wcwidth_l(__darwin_ct_rune_t _c, locale_t _l)
88 {
89 unsigned int _x;
90
91 if (_c == 0)
92 return (0);
93 _x = (unsigned int)__maskrune_l(_c, _CTYPE_SWM|_CTYPE_R, _l);
94 if ((_x & _CTYPE_SWM) != 0)
95 return ((_x & _CTYPE_SWM) >> _CTYPE_SWS);
96 return ((_x & _CTYPE_R) != 0 ? 1 : -1);
97 }
98
99 #ifndef _EXTERNALIZE_CTYPE_INLINES_
100
101 __DARWIN_CTYPE_TOP_inline int
102 digittoint_l(int c, locale_t l)
103 {
104 return (__maskrune_l(c, 0x0F, l));
105 }
106
107 __DARWIN_CTYPE_TOP_inline int
108 isalnum_l(int c, locale_t l)
109 {
110 return (__istype_l(c, _CTYPE_A|_CTYPE_D, l));
111 }
112
113 __DARWIN_CTYPE_TOP_inline int
114 isalpha_l(int c, locale_t l)
115 {
116 return (__istype_l(c, _CTYPE_A, l));
117 }
118
119 __DARWIN_CTYPE_TOP_inline int
120 isblank_l(int c, locale_t l)
121 {
122 return (__istype_l(c, _CTYPE_B, l));
123 }
124
125 __DARWIN_CTYPE_TOP_inline int
126 iscntrl_l(int c, locale_t l)
127 {
128 return (__istype_l(c, _CTYPE_C, l));
129 }
130
131 __DARWIN_CTYPE_TOP_inline int
132 isdigit_l(int c, locale_t l)
133 {
134 return (__istype_l(c, _CTYPE_D, l));
135 }
136
137 __DARWIN_CTYPE_TOP_inline int
138 isgraph_l(int c, locale_t l)
139 {
140 return (__istype_l(c, _CTYPE_G, l));
141 }
142
143 __DARWIN_CTYPE_TOP_inline int
144 ishexnumber_l(int c, locale_t l)
145 {
146 return (__istype_l(c, _CTYPE_X, l));
147 }
148
149 __DARWIN_CTYPE_TOP_inline int
150 isideogram_l(int c, locale_t l)
151 {
152 return (__istype_l(c, _CTYPE_I, l));
153 }
154
155 __DARWIN_CTYPE_TOP_inline int
156 islower_l(int c, locale_t l)
157 {
158 return (__istype_l(c, _CTYPE_L, l));
159 }
160
161 __DARWIN_CTYPE_TOP_inline int
162 isnumber_l(int c, locale_t l)
163 {
164 return (__istype_l(c, _CTYPE_D, l));
165 }
166
167 __DARWIN_CTYPE_TOP_inline int
168 isphonogram_l(int c, locale_t l)
169 {
170 return (__istype_l(c, _CTYPE_Q, l));
171 }
172
173 __DARWIN_CTYPE_TOP_inline int
174 isprint_l(int c, locale_t l)
175 {
176 return (__istype_l(c, _CTYPE_R, l));
177 }
178
179 __DARWIN_CTYPE_TOP_inline int
180 ispunct_l(int c, locale_t l)
181 {
182 return (__istype_l(c, _CTYPE_P, l));
183 }
184
185 __DARWIN_CTYPE_TOP_inline int
186 isrune_l(int c, locale_t l)
187 {
188 return (__istype_l(c, 0xFFFFFFF0L, l));
189 }
190
191 __DARWIN_CTYPE_TOP_inline int
192 isspace_l(int c, locale_t l)
193 {
194 return (__istype_l(c, _CTYPE_S, l));
195 }
196
197 __DARWIN_CTYPE_TOP_inline int
198 isspecial_l(int c, locale_t l)
199 {
200 return (__istype_l(c, _CTYPE_T, l));
201 }
202
203 __DARWIN_CTYPE_TOP_inline int
204 isupper_l(int c, locale_t l)
205 {
206 return (__istype_l(c, _CTYPE_U, l));
207 }
208
209 __DARWIN_CTYPE_TOP_inline int
210 isxdigit_l(int c, locale_t l)
211 {
212 return (__istype_l(c, _CTYPE_X, l));
213 }
214
215 __DARWIN_CTYPE_TOP_inline int
216 tolower_l(int c, locale_t l)
217 {
218 return (__tolower_l(c, l));
219 }
220
221 __DARWIN_CTYPE_TOP_inline int
222 toupper_l(int c, locale_t l)
223 {
224 return (__toupper_l(c, l));
225 }
226 #endif /* _EXTERNALIZE_CTYPE_INLINES_ */
227
228 #else /* not using inlines */
229
230 __BEGIN_DECLS
231 int digittoint_l(int, locale_t);
232 int isalnum_l(int, locale_t);
233 int isalpha_l(int, locale_t);
234 int isblank_l(int, locale_t);
235 int iscntrl_l(int, locale_t);
236 int isdigit_l(int, locale_t);
237 int isgraph_l(int, locale_t);
238 int ishexnumber_l(int, locale_t);
239 int isideogram_l(int, locale_t);
240 int islower_l(int, locale_t);
241 int isnumber_l(int, locale_t);
242 int isphonogram_l(int, locale_t);
243 int isprint_l(int, locale_t);
244 int ispunct_l(int, locale_t);
245 int isrune_l(int, locale_t);
246 int isspace_l(int, locale_t);
247 int isspecial_l(int, locale_t);
248 int isupper_l(int, locale_t);
249 int isxdigit_l(int, locale_t);
250 int tolower_l(int, locale_t);
251 int toupper_l(int, locale_t);
252 __END_DECLS
253 #endif /* using inlines */
254
255 #endif /* _XLOCALE__CTYPE_H_ */