]> git.saurik.com Git - wxWidgets.git/blob - src/common/unichar.cpp
applied patch 1683441
[wxWidgets.git] / src / common / unichar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/unichar.cpp
3 // Purpose: wxUniChar and wxUniCharRef classes
4 // Author: Vaclav Slavik
5 // Created: 2007-03-19
6 // RCS-ID: $Id$
7 // Copyright: (c) 2007 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ===========================================================================
12 // headers
13 // ===========================================================================
14
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #include "wx/unichar.h"
23
24 // ===========================================================================
25 // implementation
26 // ===========================================================================
27
28 /* static */
29 wxUniChar::unicode_type wxUniChar::From8bit(char c)
30 {
31 // all supported charsets have the first 128 characters same as ASCII:
32 if ( (unsigned char)c < 0x80 )
33 return c;
34
35 wchar_t buf[2];
36 if ( wxConvLibc.ToWChar(buf, 2, &c, 1) != 2 )
37 return wxT('?'); // FIXME-UTF8: what to use as failure character?
38 return buf[0];
39 }
40
41 /* static */
42 char wxUniChar::To8bit(wxUniChar::unicode_type c)
43 {
44 // all supported charsets have the first 128 characters same as ASCII:
45 if ( c < 0x80 )
46 return c;
47
48 wchar_t in = c;
49 char buf[2];
50 if ( wxConvLibc.FromWChar(buf, 2, &in, 1) != 2 )
51 return '?'; // FIXME-UTF8: what to use as failure character?
52 return buf[0];
53 }