2 * Copyright (c) 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 #ifndef _XLOCALE__CTYPE_H_
25 #define _XLOCALE__CTYPE_H_
31 * Use inline functions if we are allowed to and the compiler supports them.
33 #if !defined(_DONT_USE_CTYPE_INLINE_) && \
34 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
36 /* See comments in <machine/_type.h> about __darwin_ct_rune_t. */
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
);
45 __DARWIN_CTYPE_inline
int
46 __maskrune_l(__darwin_ct_rune_t _c
, unsigned long _f
, locale_t _l
)
48 /* _CurrentRuneLocale.__runetype is __uint32_t
50 * ___runetype_l(_c, _l) is unsigned long
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
;
59 int __maskrune_l(__darwin_ct_rune_t
, unsigned long, locale_t
);
65 __DARWIN_CTYPE_inline
int
66 __istype_l(__darwin_ct_rune_t _c
, unsigned long _f
, locale_t _l
)
68 return !!(isascii(_c
) ? (_DefaultRuneLocale
.__runetype
[_c
] & _f
)
69 : __maskrune_l(_c
, _f
, _l
));
72 __DARWIN_CTYPE_inline __darwin_ct_rune_t
73 __toupper_l(__darwin_ct_rune_t _c
, locale_t _l
)
75 return isascii(_c
) ? _DefaultRuneLocale
.__mapupper
[_c
]
76 : ___toupper_l(_c
, _l
);
79 __DARWIN_CTYPE_inline __darwin_ct_rune_t
80 __tolower_l(__darwin_ct_rune_t _c
, locale_t _l
)
82 return isascii(_c
) ? _DefaultRuneLocale
.__maplower
[_c
]
83 : ___tolower_l(_c
, _l
);
86 __DARWIN_CTYPE_inline
int
87 __wcwidth_l(__darwin_ct_rune_t _c
, locale_t _l
)
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);
99 #ifndef _EXTERNALIZE_CTYPE_INLINES_
101 __DARWIN_CTYPE_TOP_inline
int
102 digittoint_l(int c
, locale_t l
)
104 return (__maskrune_l(c
, 0x0F, l
));
107 __DARWIN_CTYPE_TOP_inline
int
108 isalnum_l(int c
, locale_t l
)
110 return (__istype_l(c
, _CTYPE_A
|_CTYPE_D
, l
));
113 __DARWIN_CTYPE_TOP_inline
int
114 isalpha_l(int c
, locale_t l
)
116 return (__istype_l(c
, _CTYPE_A
, l
));
119 __DARWIN_CTYPE_TOP_inline
int
120 isblank_l(int c
, locale_t l
)
122 return (__istype_l(c
, _CTYPE_B
, l
));
125 __DARWIN_CTYPE_TOP_inline
int
126 iscntrl_l(int c
, locale_t l
)
128 return (__istype_l(c
, _CTYPE_C
, l
));
131 __DARWIN_CTYPE_TOP_inline
int
132 isdigit_l(int c
, locale_t l
)
134 return (__istype_l(c
, _CTYPE_D
, l
));
137 __DARWIN_CTYPE_TOP_inline
int
138 isgraph_l(int c
, locale_t l
)
140 return (__istype_l(c
, _CTYPE_G
, l
));
143 __DARWIN_CTYPE_TOP_inline
int
144 ishexnumber_l(int c
, locale_t l
)
146 return (__istype_l(c
, _CTYPE_X
, l
));
149 __DARWIN_CTYPE_TOP_inline
int
150 isideogram_l(int c
, locale_t l
)
152 return (__istype_l(c
, _CTYPE_I
, l
));
155 __DARWIN_CTYPE_TOP_inline
int
156 islower_l(int c
, locale_t l
)
158 return (__istype_l(c
, _CTYPE_L
, l
));
161 __DARWIN_CTYPE_TOP_inline
int
162 isnumber_l(int c
, locale_t l
)
164 return (__istype_l(c
, _CTYPE_D
, l
));
167 __DARWIN_CTYPE_TOP_inline
int
168 isphonogram_l(int c
, locale_t l
)
170 return (__istype_l(c
, _CTYPE_Q
, l
));
173 __DARWIN_CTYPE_TOP_inline
int
174 isprint_l(int c
, locale_t l
)
176 return (__istype_l(c
, _CTYPE_R
, l
));
179 __DARWIN_CTYPE_TOP_inline
int
180 ispunct_l(int c
, locale_t l
)
182 return (__istype_l(c
, _CTYPE_P
, l
));
185 __DARWIN_CTYPE_TOP_inline
int
186 isrune_l(int c
, locale_t l
)
188 return (__istype_l(c
, 0xFFFFFFF0L
, l
));
191 __DARWIN_CTYPE_TOP_inline
int
192 isspace_l(int c
, locale_t l
)
194 return (__istype_l(c
, _CTYPE_S
, l
));
197 __DARWIN_CTYPE_TOP_inline
int
198 isspecial_l(int c
, locale_t l
)
200 return (__istype_l(c
, _CTYPE_T
, l
));
203 __DARWIN_CTYPE_TOP_inline
int
204 isupper_l(int c
, locale_t l
)
206 return (__istype_l(c
, _CTYPE_U
, l
));
209 __DARWIN_CTYPE_TOP_inline
int
210 isxdigit_l(int c
, locale_t l
)
212 return (__istype_l(c
, _CTYPE_X
, l
));
215 __DARWIN_CTYPE_TOP_inline
int
216 tolower_l(int c
, locale_t l
)
218 return (__tolower_l(c
, l
));
221 __DARWIN_CTYPE_TOP_inline
int
222 toupper_l(int c
, locale_t l
)
224 return (__toupper_l(c
, l
));
226 #endif /* _EXTERNALIZE_CTYPE_INLINES_ */
228 #else /* not using inlines */
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
);
253 #endif /* using inlines */
255 #endif /* _XLOCALE__CTYPE_H_ */