]>
git.saurik.com Git - wxWidgets.git/blob - src/common/unichar.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/unichar.cpp
3 // Purpose: wxUniChar and wxUniCharRef classes
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2007 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
23 #include "wx/strconv.h" // wxConvLibc
26 #include "wx/unichar.h"
28 // FIXME-UTF8: remove once UTF-8 functions moved outside
29 #include "wx/string.h"
31 // ===========================================================================
33 // ===========================================================================
35 // ---------------------------------------------------------------------------
37 // ---------------------------------------------------------------------------
40 wxUniChar::value_type
wxUniChar::From8bit(char c
)
42 // all supported charsets have the first 128 characters same as ASCII:
43 if ( (unsigned char)c
< 0x80 )
47 if ( wxConvLibc
.ToWChar(buf
, 2, &c
, 1) != 2 )
48 return wxT('?'); // FIXME-UTF8: what to use as failure character?
53 char wxUniChar::To8bit(wxUniChar::value_type c
)
55 // all supported charsets have the first 128 characters same as ASCII:
61 if ( wxConvLibc
.FromWChar(buf
, 2, &in
, 1) != 2 )
62 return '?'; // FIXME-UTF8: what to use as failure character?
67 // ---------------------------------------------------------------------------
69 // ---------------------------------------------------------------------------
71 #if wxUSE_UNICODE_UTF8
72 wxUniCharRef
& wxUniCharRef::operator=(const wxUniChar
& c
)
74 wxString::Utf8CharBuffer
utf(wxString::EncodeChar(c
));
75 size_t lenOld
= wxString::GetUtf8CharLength(*m_pos
);
76 size_t lenNew
= wxString::GetUtf8CharLength(utf
[0]);
78 if ( lenNew
== lenOld
)
81 for ( size_t i
= 0; i
< lenNew
; ++i
, ++pos
)
86 size_t idx
= m_pos
- m_str
.begin();
88 m_str
.replace(m_pos
, m_pos
+ lenOld
, utf
, lenNew
);
90 // this is needed to keep m_pos valid:
91 m_pos
= m_str
.begin() + idx
;
96 #endif // wxUSE_UNICODE_UTF8