]>
git.saurik.com Git - wxWidgets.git/blob - src/common/xlocale.cpp
1 //////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/xlocale.cpp
3 // Purpose: xlocale wrappers/impl to provide some xlocale wrappers
4 // Author: Brian Vanderburg II, Vadim Zeitlin
7 // Copyright: (c) 2008 Brian Vanderburg II
8 // 2008 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
29 #include "wx/module.h"
32 #include "wx/xlocale.h"
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 // This is the C locale object, it is created on demand
39 static wxXLocale
*gs_cLocale
= NULL
;
41 // ============================================================================
43 // ============================================================================
45 // ----------------------------------------------------------------------------
46 // Module for gs_cLocale cleanup
47 // ----------------------------------------------------------------------------
49 class wxXLocaleModule
: public wxModule
52 virtual bool OnInit() { return true; }
53 virtual void OnExit() { wxDELETE(gs_cLocale
); }
55 DECLARE_DYNAMIC_CLASS(wxXLocaleModule
)
58 IMPLEMENT_DYNAMIC_CLASS(wxXLocaleModule
, wxModule
)
61 // ============================================================================
62 // wxXLocale implementation
63 // ============================================================================
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
70 wxXLocale
& wxXLocale::GetCLocale()
74 gs_cLocale
= new wxXLocale(wx_static_cast(wxXLocaleCTag
*, NULL
));
80 #ifdef wxHAS_XLOCALE_SUPPORT
82 wxXLocale::wxXLocale(wxLanguage lang
)
84 const wxLanguageInfo
* const info
= wxLocale::GetLanguageInfo(lang
);
91 Init(info
->GetLocaleName().c_str());
95 #if wxCHECK_VISUALC_VERSION(8)
97 // ----------------------------------------------------------------------------
98 // implementation using MSVC locale API
99 // ----------------------------------------------------------------------------
101 void wxXLocale::Init(const char *loc
)
103 m_locale
= _create_locale(LC_ALL
, loc
);
106 void wxXLocale::Free()
109 _free_locale(m_locale
);
112 #elif defined(HAVE_LOCALE_T)
114 // ----------------------------------------------------------------------------
115 // implementation using xlocale API
116 // ----------------------------------------------------------------------------
118 void wxXLocale::Init(const char *loc
)
120 m_locale
= newlocale(LC_ALL_MASK
, loc
, NULL
);
123 void wxXLocale::Free()
126 freelocale(m_locale
);
130 #error "Unknown xlocale support."
133 #endif // wxHAS_XLOCALE_SUPPORT
135 #ifndef wxHAS_XLOCALE_SUPPORT
137 // ============================================================================
138 // Implementation of wxFoo_l() functions for "C" locale without xlocale support
139 // ============================================================================
141 // ----------------------------------------------------------------------------
142 // character classification and transformation functions
143 // ----------------------------------------------------------------------------
145 // lookup table and macros for character type functions
146 #define CTYPE_ALNUM 0x0001
147 #define CTYPE_ALPHA 0x0002
148 #define CTYPE_CNTRL 0x0004
149 #define CTYPE_DIGIT 0x0008
150 #define CTYPE_GRAPH 0x0010
151 #define CTYPE_LOWER 0x0020
152 #define CTYPE_PRINT 0x0040
153 #define CTYPE_PUNCT 0x0080
154 #define CTYPE_SPACE 0x0100
155 #define CTYPE_UPPER 0x0200
156 #define CTYPE_XDIGIT 0x0400
158 static unsigned int gs_lookup
[] =
160 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
161 0x0004, 0x0104, 0x0104, 0x0104, 0x0104, 0x0104, 0x0004, 0x0004,
162 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
163 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004,
164 0x0140, 0x00D0, 0x00D0, 0x00D0, 0x00D0, 0x00D0, 0x00D0, 0x00D0,
165 0x00D0, 0x00D0, 0x00D0, 0x00D0, 0x00D0, 0x00D0, 0x00D0, 0x00D0,
166 0x0459, 0x0459, 0x0459, 0x0459, 0x0459, 0x0459, 0x0459, 0x0459,
167 0x0459, 0x0459, 0x00D0, 0x00D0, 0x00D0, 0x00D0, 0x00D0, 0x00D0,
168 0x00D0, 0x0653, 0x0653, 0x0653, 0x0653, 0x0653, 0x0653, 0x0253,
169 0x0253, 0x0253, 0x0253, 0x0253, 0x0253, 0x0253, 0x0253, 0x0253,
170 0x0253, 0x0253, 0x0253, 0x0253, 0x0253, 0x0253, 0x0253, 0x0253,
171 0x0253, 0x0253, 0x0253, 0x00D0, 0x00D0, 0x00D0, 0x00D0, 0x00D0,
172 0x00D0, 0x0473, 0x0473, 0x0473, 0x0473, 0x0473, 0x0473, 0x0073,
173 0x0073, 0x0073, 0x0073, 0x0073, 0x0073, 0x0073, 0x0073, 0x0073,
174 0x0073, 0x0073, 0x0073, 0x0073, 0x0073, 0x0073, 0x0073, 0x0073,
175 0x0073, 0x0073, 0x0073, 0x00D0, 0x00D0, 0x00D0, 0x00D0, 0x0004
179 #define CTYPE_TEST(c, t) ( (c) <= 127 && (gs_lookup[(c)] & (t)) )
183 #define GEN_ISFUNC(name, test) \
184 int name(const wxUniChar& c, const wxXLocale& loc) \
186 wxCHECK(loc.IsOk(), false); \
187 return CTYPE_TEST(c.GetValue(), test); \
190 GEN_ISFUNC(wxIsalnum_l
, CTYPE_ALNUM
)
191 GEN_ISFUNC(wxIsalpha_l
, CTYPE_ALPHA
)
192 GEN_ISFUNC(wxIscntrl_l
, CTYPE_CNTRL
)
193 GEN_ISFUNC(wxIsdigit_l
, CTYPE_DIGIT
)
194 GEN_ISFUNC(wxIsgraph_l
, CTYPE_GRAPH
)
195 GEN_ISFUNC(wxIslower_l
, CTYPE_LOWER
)
196 GEN_ISFUNC(wxIsprint_l
, CTYPE_PRINT
)
197 GEN_ISFUNC(wxIspunct_l
, CTYPE_PUNCT
)
198 GEN_ISFUNC(wxIsspace_l
, CTYPE_SPACE
)
199 GEN_ISFUNC(wxIsupper_l
, CTYPE_UPPER
)
200 GEN_ISFUNC(wxIsxdigit_l
, CTYPE_XDIGIT
)
202 int wxTolower_l(const wxUniChar
& c
, const wxXLocale
& loc
)
204 wxCHECK(loc
.IsOk(), false);
206 if(CTYPE_TEST(c
.GetValue(), CTYPE_UPPER
))
208 return c
- 'A' + 'a';
214 int wxToupper_l(const wxUniChar
& c
, const wxXLocale
& loc
)
216 wxCHECK(loc
.IsOk(), false);
218 if(CTYPE_TEST(c
.GetValue(), CTYPE_LOWER
))
220 return c
- 'a' + 'A';
226 #endif // !defined(wxHAS_XLOCALE_SUPPORT)
228 #endif // wxUSE_XLOCALE