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