Better handling of supplementary wxUniChar values in some of wxString methods
On MSW, the Unicode code point is now properly encoded as UTF-16 when assigned or appended to a wxString. Closes #11827
This commit is contained in:
@@ -44,9 +44,36 @@ struct WXDLLIMPEXP_BASE wxStringOperationsWchar
|
||||
static ptrdiff_t DiffIters(const Iterator& i1, const Iterator& i2)
|
||||
{ return i1 - i2; }
|
||||
|
||||
#if wxUSE_UNICODE_UTF16
|
||||
// encodes th characters as UTF-16:
|
||||
struct Utf16CharBuffer
|
||||
{
|
||||
Utf16CharBuffer() : data() {}
|
||||
wchar_t data[3];
|
||||
operator const wchar_t*() const { return data; }
|
||||
};
|
||||
static Utf16CharBuffer EncodeChar(const wxUniChar& ch);
|
||||
static wxWCharBuffer EncodeNChars(size_t n, const wxUniChar& ch);
|
||||
static bool IsSingleCodeUnitCharacter(const wxUniChar& ch)
|
||||
{ return !ch.IsSupplementary(); }
|
||||
#else
|
||||
// encodes the character to a form used to represent it in internal
|
||||
// representation (returns a string in UTF8 version)
|
||||
static wxChar EncodeChar(const wxUniChar& ch) { return (wxChar)ch; }
|
||||
// representation
|
||||
struct SingleCharBuffer
|
||||
{
|
||||
SingleCharBuffer() : data() {}
|
||||
wxChar data[2];
|
||||
operator const wxChar*() const { return data; }
|
||||
};
|
||||
static SingleCharBuffer EncodeChar(const wxUniChar& ch)
|
||||
{
|
||||
SingleCharBuffer buf;
|
||||
buf.data[0] = (wxChar)ch;
|
||||
return buf;
|
||||
}
|
||||
static wxWxCharBuffer EncodeNChars(size_t n, const wxUniChar& ch);
|
||||
static bool IsSingleCodeUnitCharacter(const wxUniChar&) { return true; }
|
||||
#endif
|
||||
|
||||
static wxUniChar DecodeChar(const wxStringImpl::const_iterator& i)
|
||||
{ return *i; }
|
||||
@@ -134,6 +161,9 @@ struct WXDLLIMPEXP_BASE wxStringOperationsUtf8
|
||||
return dist;
|
||||
}
|
||||
|
||||
static bool IsSingleCodeUnitCharacter(const wxUniChar& ch)
|
||||
{ return ch.IsAscii(); }
|
||||
|
||||
// encodes the character as UTF-8:
|
||||
typedef wxUniChar::Utf8CharBuffer Utf8CharBuffer;
|
||||
static Utf8CharBuffer EncodeChar(const wxUniChar& ch)
|
||||
|
Reference in New Issue
Block a user