2 * Copyright (c) 2011 The FreeBSD Foundation
5 * This software was developed by David Chisnall under sponsorship from
6 * the FreeBSD Foundation.
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.
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
31 #error This header should only be included by <xlocale.h>, never directly.
34 #ifndef _XLOCALE_CTYPE_H_
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*);
43 #ifndef _XLOCALE_INLINE
44 #if __GNUC__ && !__GNUC_STDC_INLINE__
45 #define _XLOCALE_INLINE extern inline
47 #define _XLOCALE_INLINE inline
51 #ifdef XLOCALE_WCTYPES
53 __maskrune_l(__ct_rune_t _c, unsigned long _f, locale_t locale)
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;
62 __istype_l(__ct_rune_t _c, unsigned long _f, locale_t locale)
64 return (!!__maskrune_l(_c, _f, locale));
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); }
72 __sbmaskrune_l(__ct_rune_t _c, unsigned long _f, locale_t locale)
75 _RuneLocale *runes = __runes_for_locale(locale, &mb_sb_limit);
76 return (_c < 0 || _c >= mb_sb_limit) ? 0 :
77 runes->__runetype[_c] & _f;
81 __sbistype_l(__ct_rune_t _c, unsigned long _f, locale_t locale)
83 return (!!__sbmaskrune_l(_c, _f, locale));
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); }
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
111 #ifdef XLOCALE_WCTYPES
112 _XLOCALE_INLINE int towlower_l(int c, locale_t locale)
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];
119 _XLOCALE_INLINE int towupper_l(int c, locale_t locale)
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];
127 __wcwidth_l(__ct_rune_t _c, locale_t locale)
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);
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
145 _XLOCALE_INLINE int digittoint_l(int c, locale_t locale)
146 { return __sbmaskrune_l((c), 0xFF, locale); }
148 _XLOCALE_INLINE int tolower_l(int c, locale_t locale)
151 _RuneLocale *runes = __runes_for_locale(locale, &mb_sb_limit);
152 return (c < 0 || c >= mb_sb_limit) ? c :
153 runes->__maplower[c];
155 _XLOCALE_INLINE int toupper_l(int c, locale_t locale)
158 _RuneLocale *runes = __runes_for_locale(locale, &mb_sb_limit);
159 return (c < 0 || c >= mb_sb_limit) ? c :
160 runes->__mapupper[c];