]> git.saurik.com Git - apple/libc.git/blob - include/xlocale/_ctype.h
Libc-391.5.22.tar.gz
[apple/libc.git] / include / xlocale / _ctype.h
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
28 int digittoint_l(int, locale_t);
29 int isalnum_l(int, locale_t);
30 int isalpha_l(int, locale_t);
31 int isblank_l(int, locale_t);
32 int iscntrl_l(int, locale_t);
33 int isdigit_l(int, locale_t);
34 int isgraph_l(int, locale_t);
35 int ishexnumber_l(int, locale_t);
36 int isideogram_l(int, locale_t);
37 int islower_l(int, locale_t);
38 int isnumber_l(int, locale_t);
39 int isphonogram_l(int, locale_t);
40 int isprint_l(int, locale_t);
41 int ispunct_l(int, locale_t);
42 int isrune_l(int, locale_t);
43 int isspace_l(int, locale_t);
44 int isspecial_l(int, locale_t);
45 int isupper_l(int, locale_t);
46 int isxdigit_l(int, locale_t);
47 int tolower_l(int, locale_t);
48 int 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
75 unsigned 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__
88 static __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
97 int __maskrune_l(__darwin_ct_rune_t, unsigned long, locale_t);
98 __END_DECLS
99 //Begin-Libc
100 #endif /* __LIBC__ */
101 //End-Libc
102
103 static __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
110 static __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
117 static __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
124 static __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
140 int __maskrune_l(__darwin_ct_rune_t, unsigned long, locale_t);
141 int __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);
144 int __wcwidth_l(__darwin_ct_rune_t, locale_t);
145 __END_DECLS
146 #endif /* using inlines */
147
148 #endif /* _XLOCALE__CTYPE_H_ */