]>
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"
27 #include "wx/stringops.h"
29 // ===========================================================================
31 // ===========================================================================
33 // ---------------------------------------------------------------------------
35 // ---------------------------------------------------------------------------
38 wxUniChar::value_type
wxUniChar::From8bit(char c
)
40 // all supported charsets have the first 128 characters same as ASCII:
41 if ( (unsigned char)c
< 0x80 )
45 if ( wxConvLibc
.ToWChar(buf
, 2, &c
, 1) != 2 )
46 return wxT('?'); // FIXME-UTF8: what to use as failure character?
51 char wxUniChar::To8bit(wxUniChar::value_type c
)
53 // all supported charsets have the first 128 characters same as ASCII:
59 if ( wxConvLibc
.FromWChar(buf
, 2, &in
, 1) != 2 )
60 return '?'; // FIXME-UTF8: what to use as failure character?
65 // ---------------------------------------------------------------------------
67 // ---------------------------------------------------------------------------
69 #if wxUSE_UNICODE_UTF8
70 wxUniChar
wxUniCharRef::UniChar() const
72 return wxStringOperations::DecodeChar(m_pos
);
75 wxUniCharRef
& wxUniCharRef::operator=(const wxUniChar
& c
)
77 wxStringOperations::Utf8CharBuffer
utf(wxStringOperations::EncodeChar(c
));
78 size_t lenOld
= wxStringOperations::GetUtf8CharLength(*m_pos
);
79 size_t lenNew
= wxStringOperations::GetUtf8CharLength(utf
[0]);
81 if ( lenNew
== lenOld
)
84 for ( size_t i
= 0; i
< lenNew
; ++i
, ++pos
)
89 size_t idx
= m_pos
- m_str
.begin();
91 m_str
.replace(m_pos
, m_pos
+ lenOld
, utf
, lenNew
);
93 // this is needed to keep m_pos valid:
94 m_pos
= m_str
.begin() + idx
;
99 #endif // wxUSE_UNICODE_UTF8