]> git.saurik.com Git - apple/libc.git/blame - include/xlocale/_ctype.h
Libc-391.5.22.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
27__BEGIN_DECLS
28int digittoint_l(int, locale_t);
29int isalnum_l(int, locale_t);
30int isalpha_l(int, locale_t);
31int isblank_l(int, locale_t);
32int iscntrl_l(int, locale_t);
33int isdigit_l(int, locale_t);
34int isgraph_l(int, locale_t);
35int ishexnumber_l(int, locale_t);
36int isideogram_l(int, locale_t);
37int islower_l(int, locale_t);
38int isnumber_l(int, locale_t);
39int isphonogram_l(int, locale_t);
40int isprint_l(int, locale_t);
41int ispunct_l(int, locale_t);
42int isrune_l(int, locale_t);
43int isspace_l(int, locale_t);
44int isspecial_l(int, locale_t);
45int isupper_l(int, locale_t);
46int isxdigit_l(int, locale_t);
47int tolower_l(int, locale_t);
48int toupper_l(int, locale_t);
49__END_DECLS
50
51#define digittoint_l(c, l) __maskrune_l((c), 0xFF, (l))
52#define ishexnumber_l(c, l) __istype_l((c), _CTYPE_X, (l))
53#define isideogram_l(c, l) __istype_l((c), _CTYPE_I, (l))
54#define isnumber_l(c, l) __istype_l((c), _CTYPE_D, (l))
55#define isphonogram_l(c, l) __istype_l((c), _CTYPE_Q, (l))
56#define isrune_l(c, l) __istype_l((c), 0xFFFFFF00L, (l))
57#define isspecial_l(c, l) __istype_l((c), _CTYPE_T, (l))
58#define isalnum_l(c, l) __istype_l((c), (_CTYPE_A|_CTYPE_D), (l))
59#define isalpha_l(c, l) __istype_l((c), _CTYPE_A, (l))
60#define isblank_l(c, l) __istype_l((c), _CTYPE_B, (l))
61#define iscntrl_l(c, l) __istype_l((c), _CTYPE_C, (l))
62#define isdigit_l(c, l) __istype_l((c), _CTYPE_D, (l))
63#define isgraph_l(c, l) __istype_l((c), _CTYPE_G, (l))
64#define islower_l(c, l) __istype_l((c), _CTYPE_L, (l))
65#define isprint_l(c, l) __istype_l((c), _CTYPE_R, (l))
66#define ispunct_l(c, l) __istype_l((c), _CTYPE_P, (l))
67#define isspace_l(c, l) __istype_l((c), _CTYPE_S, (l))
68#define isupper_l(c, l) __istype_l((c), _CTYPE_U, (l))
69#define isxdigit_l(c, l) __istype_l((c), _CTYPE_X, (l))
70#define tolower_l(c, l) __tolower_l(c, (l))
71#define toupper_l(c, l) __toupper_l(c, (l))
72
73/* See comments in <machine/_type.h> about __darwin_ct_rune_t. */
74__BEGIN_DECLS
75unsigned long ___runetype_l(__darwin_ct_rune_t, locale_t);
76__darwin_ct_rune_t ___tolower_l(__darwin_ct_rune_t, locale_t);
77__darwin_ct_rune_t ___toupper_l(__darwin_ct_rune_t, locale_t);
78__END_DECLS
79
80/*
81 * Use inline functions if we are allowed to and the compiler supports them.
82 */
83#if !defined(_DONT_USE_CTYPE_INLINE_) && \
84 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
85
86//Begin-Libc
87#ifdef __LIBC__
88static __inline int
89__maskrune_l(__darwin_ct_rune_t _c, unsigned long _f, locale_t _l)
90{
91 return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype_l(_c, _l) :
92 __locale_ptr(_l)->__lc_ctype->_CurrentRuneLocale.__runetype[_c]) & _f;
93}
94#else /* !__LIBC__ */
95//End-Libc
96__BEGIN_DECLS
97int __maskrune_l(__darwin_ct_rune_t, unsigned long, locale_t);
98__END_DECLS
99//Begin-Libc
100#endif /* __LIBC__ */
101//End-Libc
102
103static __inline int
104__istype_l(__darwin_ct_rune_t _c, unsigned long _f, locale_t _l)
105{
106 return !!(isascii(_c) ? (_DefaultRuneLocale.__runetype[_c] & _f)
107 : __maskrune_l(_c, _f, _l));
108}
109
110static __inline __darwin_ct_rune_t
111__toupper_l(__darwin_ct_rune_t _c, locale_t _l)
112{
113 return isascii(_c) ? _DefaultRuneLocale.__mapupper[_c]
114 : ___toupper_l(_c, _l);
115}
116
117static __inline __darwin_ct_rune_t
118__tolower_l(__darwin_ct_rune_t _c, locale_t _l)
119{
120 return isascii(_c) ? _DefaultRuneLocale.__maplower[_c]
121 : ___tolower_l(_c, _l);
122}
123
124static __inline int
125__wcwidth_l(__darwin_ct_rune_t _c, locale_t _l)
126{
127 unsigned int _x;
128
129 if (_c == 0)
130 return (0);
131 _x = (unsigned int)__maskrune_l(_c, _CTYPE_SWM|_CTYPE_R, _l);
132 if ((_x & _CTYPE_SWM) != 0)
133 return ((_x & _CTYPE_SWM) >> _CTYPE_SWS);
134 return ((_x & _CTYPE_R) != 0 ? 1 : -1);
135}
136
137#else /* not using inlines */
138
139__BEGIN_DECLS
140int __maskrune_l(__darwin_ct_rune_t, unsigned long, locale_t);
141int __istype_l(__darwin_ct_rune_t, unsigned long, locale_t);
142__darwin_ct_rune_t __toupper_l(__darwin_ct_rune_t, locale_t);
143__darwin_ct_rune_t __tolower_l(__darwin_ct_rune_t, locale_t);
144int __wcwidth_l(__darwin_ct_rune_t, locale_t);
145__END_DECLS
146#endif /* using inlines */
147
148#endif /* _XLOCALE__CTYPE_H_ */