]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/_xlocale_ctype.h
Remove _Complex_I workaround from <tgmath.h>.
[FreeBSD/FreeBSD.git] / include / _xlocale_ctype.h
1 /*-
2  * Copyright (c) 2011 The FreeBSD Foundation
3  * All rights reserved.
4  *
5  * This software was developed by David Chisnall under sponsorship from
6  * the FreeBSD Foundation.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions * are met:
10  * 1.  Redistributions of source code must retain the above copyright notice,
11  *     this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  *    this list of conditions and the following disclaimer in the documentation
14  *    and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 #ifndef _XLOCALE_H_
31 #error This header should only be included by <xlocale.h>, never directly.
32 #endif
33
34 #ifndef _XLOCALE_CTYPE_H_
35 __BEGIN_DECLS
36 unsigned long   ___runetype_l(__ct_rune_t, locale_t) __pure;
37 __ct_rune_t     ___tolower_l(__ct_rune_t, locale_t) __pure;
38 __ct_rune_t     ___toupper_l(__ct_rune_t, locale_t) __pure;
39 _RuneLocale     *__runes_for_locale(locale_t, int*);
40 __END_DECLS
41 #endif
42
43 #ifndef _XLOCALE_INLINE
44 #if __GNUC__ && !__GNUC_STDC_INLINE__
45 #define _XLOCALE_INLINE extern inline
46 #else
47 #define _XLOCALE_INLINE inline
48 #endif
49 #endif
50
51 #ifdef XLOCALE_WCTYPES
52 static __inline int
53 __maskrune_l(__ct_rune_t _c, unsigned long _f, locale_t locale)
54 {
55         int mb_sb_limit;
56         _RuneLocale *runes = __runes_for_locale(locale, &mb_sb_limit);
57         return (_c < 0 || _c >= _CACHED_RUNES) ? ___runetype_l(_c, locale) :
58                runes->__runetype[_c] & _f;
59 }
60
61 static __inline int
62 __istype_l(__ct_rune_t _c, unsigned long _f, locale_t locale)
63 {
64         return (!!__maskrune_l(_c, _f, locale));
65 }
66
67 #define XLOCALE_ISCTYPE(fname, cat) \
68                 _XLOCALE_INLINE int isw##fname##_l(int c, locale_t l)\
69                 { return __istype_l(c, cat, l); }
70 #else
71 static __inline int
72 __sbmaskrune_l(__ct_rune_t _c, unsigned long _f, locale_t locale)
73 {
74         int mb_sb_limit;
75         _RuneLocale *runes = __runes_for_locale(locale, &mb_sb_limit);
76         return (_c < 0 || _c >= mb_sb_limit) ? 0 :
77                runes->__runetype[_c] & _f;
78 }
79
80 static __inline int
81 __sbistype_l(__ct_rune_t _c, unsigned long _f, locale_t locale)
82 {
83         return (!!__sbmaskrune_l(_c, _f, locale));
84 }
85
86 #define XLOCALE_ISCTYPE(fname, cat) \
87                 _XLOCALE_INLINE int is##fname##_l(int c, locale_t l)\
88                 { return __sbistype_l(c, cat, l); }
89 #endif
90
91 XLOCALE_ISCTYPE(alnum, _CTYPE_A|_CTYPE_D)
92 XLOCALE_ISCTYPE(alpha, _CTYPE_A)
93 XLOCALE_ISCTYPE(blank, _CTYPE_B)
94 XLOCALE_ISCTYPE(cntrl, _CTYPE_C)
95 XLOCALE_ISCTYPE(digit, _CTYPE_D)
96 XLOCALE_ISCTYPE(graph, _CTYPE_G)
97 XLOCALE_ISCTYPE(hexnumber, _CTYPE_X)
98 XLOCALE_ISCTYPE(ideogram, _CTYPE_I)
99 XLOCALE_ISCTYPE(lower, _CTYPE_L)
100 XLOCALE_ISCTYPE(number, _CTYPE_D)
101 XLOCALE_ISCTYPE(phonogram, _CTYPE_Q)
102 XLOCALE_ISCTYPE(print, _CTYPE_R)
103 XLOCALE_ISCTYPE(punct, _CTYPE_P)
104 XLOCALE_ISCTYPE(rune, 0xFFFFFF00L)
105 XLOCALE_ISCTYPE(space, _CTYPE_S)
106 XLOCALE_ISCTYPE(special, _CTYPE_T)
107 XLOCALE_ISCTYPE(upper, _CTYPE_U)
108 XLOCALE_ISCTYPE(xdigit, _CTYPE_X)
109 #undef XLOCALE_ISCTYPE
110
111 #ifdef XLOCALE_WCTYPES
112 _XLOCALE_INLINE int towlower_l(int c, locale_t locale)
113 {
114         int mb_sb_limit;
115         _RuneLocale *runes = __runes_for_locale(locale, &mb_sb_limit);
116         return (c < 0 || c >= _CACHED_RUNES) ? ___tolower_l(c, locale) :
117                runes->__maplower[c];
118 }
119 _XLOCALE_INLINE int towupper_l(int c, locale_t locale)
120 {
121         int mb_sb_limit;
122         _RuneLocale *runes = __runes_for_locale(locale, &mb_sb_limit);
123         return (c < 0 || c >= _CACHED_RUNES) ? ___toupper_l(c, locale) :
124                runes->__mapupper[c];
125 }
126 _XLOCALE_INLINE int
127 __wcwidth_l(__ct_rune_t _c, locale_t locale)
128 {
129         unsigned int _x;
130
131         if (_c == 0)
132                 return (0);
133         _x = (unsigned int)__maskrune_l(_c, _CTYPE_SWM|_CTYPE_R, locale);
134         if ((_x & _CTYPE_SWM) != 0)
135                 return ((_x & _CTYPE_SWM) >> _CTYPE_SWS);
136         return ((_x & _CTYPE_R) != 0 ? 1 : -1);
137 }
138 int iswctype_l(wint_t wc, wctype_t charclass, locale_t locale);
139 wctype_t wctype_l(const char *property, locale_t locale);
140 wint_t towctrans_l(wint_t wc, wctrans_t desc, locale_t locale);
141 wint_t nextwctype_l(wint_t wc, wctype_t wct, locale_t locale);
142 wctrans_t wctrans_l(const char *charclass, locale_t locale);
143 #undef XLOCALE_WCTYPES
144 #else
145 _XLOCALE_INLINE int digittoint_l(int c, locale_t locale)
146 { return __sbmaskrune_l((c), 0xFF, locale); }
147
148 _XLOCALE_INLINE int tolower_l(int c, locale_t locale)
149 {
150         int mb_sb_limit;
151         _RuneLocale *runes = __runes_for_locale(locale, &mb_sb_limit);
152         return (c < 0 || c >= mb_sb_limit) ? c :
153                runes->__maplower[c];
154 }
155 _XLOCALE_INLINE int toupper_l(int c, locale_t locale)
156 {
157         int mb_sb_limit;
158         _RuneLocale *runes = __runes_for_locale(locale, &mb_sb_limit);
159         return (c < 0 || c >= mb_sb_limit) ? c :
160                runes->__mapupper[c];
161 }
162 #endif