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_
28 * Use inline functions if we are allowed to and the compiler supports them.
30 #if !defined(_DONT_USE_CTYPE_INLINE_) && \
31 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
33 /* See comments in <machine/_type.h> about __darwin_ct_rune_t. */
35 unsigned 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
);
42 __DARWIN_CTYPE_inline
int
43 __maskrune_l(__darwin_ct_rune_t _c
, unsigned long _f
, locale_t _l
)
45 /* _CurrentRuneLocale.__runetype is __uint32_t
47 * ___runetype_l(_c, _l) is unsigned long
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
;
56 int __maskrune_l(__darwin_ct_rune_t
, unsigned long, locale_t
);
62 __DARWIN_CTYPE_inline
int
63 __istype_l(__darwin_ct_rune_t _c
, unsigned long _f
, locale_t _l
)
65 return !!(isascii(_c
) ? (_DefaultRuneLocale
.__runetype
[_c
] & _f
)
66 : __maskrune_l(_c
, _f
, _l
));
69 __DARWIN_CTYPE_inline __darwin_ct_rune_t
70 __toupper_l(__darwin_ct_rune_t _c
, locale_t _l
)
72 return isascii(_c
) ? _DefaultRuneLocale
.__mapupper
[_c
]
73 : ___toupper_l(_c
, _l
);
76 __DARWIN_CTYPE_inline __darwin_ct_rune_t
77 __tolower_l(__darwin_ct_rune_t _c
, locale_t _l
)
79 return isascii(_c
) ? _DefaultRuneLocale
.__maplower
[_c
]
80 : ___tolower_l(_c
, _l
);
83 __DARWIN_CTYPE_inline
int
84 __wcwidth_l(__darwin_ct_rune_t _c
, locale_t _l
)
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);
96 #ifndef _EXTERNALIZE_CTYPE_INLINES_
98 __DARWIN_CTYPE_TOP_inline
int
99 digittoint_l(int c
, locale_t l
)
101 return (__maskrune_l(c
, 0x0F, l
));
104 __DARWIN_CTYPE_TOP_inline
int
105 isalnum_l(int c
, locale_t l
)
107 return (__istype_l(c
, _CTYPE_A
|_CTYPE_D
, l
));
110 __DARWIN_CTYPE_TOP_inline
int
111 isalpha_l(int c
, locale_t l
)
113 return (__istype_l(c
, _CTYPE_A
, l
));
116 __DARWIN_CTYPE_TOP_inline
int
117 isblank_l(int c
, locale_t l
)
119 return (__istype_l(c
, _CTYPE_B
, l
));
122 __DARWIN_CTYPE_TOP_inline
int
123 iscntrl_l(int c
, locale_t l
)
125 return (__istype_l(c
, _CTYPE_C
, l
));
128 __DARWIN_CTYPE_TOP_inline
int
129 isdigit_l(int c
, locale_t l
)
131 return (__istype_l(c
, _CTYPE_D
, l
));
134 __DARWIN_CTYPE_TOP_inline
int
135 isgraph_l(int c
, locale_t l
)
137 return (__istype_l(c
, _CTYPE_G
, l
));
140 __DARWIN_CTYPE_TOP_inline
int
141 ishexnumber_l(int c
, locale_t l
)
143 return (__istype_l(c
, _CTYPE_X
, l
));
146 __DARWIN_CTYPE_TOP_inline
int
147 isideogram_l(int c
, locale_t l
)
149 return (__istype_l(c
, _CTYPE_I
, l
));
152 __DARWIN_CTYPE_TOP_inline
int
153 islower_l(int c
, locale_t l
)
155 return (__istype_l(c
, _CTYPE_L
, l
));
158 __DARWIN_CTYPE_TOP_inline
int
159 isnumber_l(int c
, locale_t l
)
161 return (__istype_l(c
, _CTYPE_D
, l
));
164 __DARWIN_CTYPE_TOP_inline
int
165 isphonogram_l(int c
, locale_t l
)
167 return (__istype_l(c
, _CTYPE_Q
, l
));
170 __DARWIN_CTYPE_TOP_inline
int
171 isprint_l(int c
, locale_t l
)
173 return (__istype_l(c
, _CTYPE_R
, l
));
176 __DARWIN_CTYPE_TOP_inline
int
177 ispunct_l(int c
, locale_t l
)
179 return (__istype_l(c
, _CTYPE_P
, l
));
182 __DARWIN_CTYPE_TOP_inline
int
183 isrune_l(int c
, locale_t l
)
185 return (__istype_l(c
, 0xFFFFFFF0L
, l
));
188 __DARWIN_CTYPE_TOP_inline
int
189 isspace_l(int c
, locale_t l
)
191 return (__istype_l(c
, _CTYPE_S
, l
));
194 __DARWIN_CTYPE_TOP_inline
int
195 isspecial_l(int c
, locale_t l
)
197 return (__istype_l(c
, _CTYPE_T
, l
));
200 __DARWIN_CTYPE_TOP_inline
int
201 isupper_l(int c
, locale_t l
)
203 return (__istype_l(c
, _CTYPE_U
, l
));
206 __DARWIN_CTYPE_TOP_inline
int
207 isxdigit_l(int c
, locale_t l
)
209 return (__istype_l(c
, _CTYPE_X
, l
));
212 __DARWIN_CTYPE_TOP_inline
int
213 tolower_l(int c
, locale_t l
)
215 return (__tolower_l(c
, l
));
218 __DARWIN_CTYPE_TOP_inline
int
219 toupper_l(int c
, locale_t l
)
221 return (__toupper_l(c
, l
));
223 #endif /* _EXTERNALIZE_CTYPE_INLINES_ */
225 #else /* not using inlines */
228 int digittoint_l(int, locale_t
);
229 int isalnum_l(int, locale_t
);
230 int isalpha_l(int, locale_t
);
231 int isblank_l(int, locale_t
);
232 int iscntrl_l(int, locale_t
);
233 int isdigit_l(int, locale_t
);
234 int isgraph_l(int, locale_t
);
235 int ishexnumber_l(int, locale_t
);
236 int isideogram_l(int, locale_t
);
237 int islower_l(int, locale_t
);
238 int isnumber_l(int, locale_t
);
239 int isphonogram_l(int, locale_t
);
240 int isprint_l(int, locale_t
);
241 int ispunct_l(int, locale_t
);
242 int isrune_l(int, locale_t
);
243 int isspace_l(int, locale_t
);
244 int isspecial_l(int, locale_t
);
245 int isupper_l(int, locale_t
);
246 int isxdigit_l(int, locale_t
);
247 int tolower_l(int, locale_t
);
248 int toupper_l(int, locale_t
);
250 #endif /* using inlines */
252 #endif /* _XLOCALE__CTYPE_H_ */