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