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:
@@ -27,6 +27,68 @@
|
||||
// implementation
|
||||
// ===========================================================================
|
||||
|
||||
#if wxUSE_UNICODE_WCHAR || !wxUSE_UNICODE
|
||||
|
||||
#if wxUSE_UNICODE_UTF16
|
||||
|
||||
wxStringOperationsWchar::Utf16CharBuffer wxStringOperationsWchar::EncodeChar(const wxUniChar& ch)
|
||||
{
|
||||
Utf16CharBuffer buf;
|
||||
if ( ch.IsSupplementary() )
|
||||
{
|
||||
buf.data[0] = (wchar_t)ch.HighSurrogate();
|
||||
buf.data[1] = (wchar_t)ch.LowSurrogate();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Assume ch is a BMP character
|
||||
buf.data[0] = (wchar_t)ch;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
wxWCharBuffer wxStringOperationsWchar::EncodeNChars(size_t n, const wxUniChar& ch)
|
||||
{
|
||||
if ( ch.IsSupplementary() )
|
||||
{
|
||||
wxWCharBuffer buf(n * 2);
|
||||
wchar_t s[2] = {
|
||||
(wchar_t)ch.HighSurrogate(),
|
||||
(wchar_t)ch.LowSurrogate(),
|
||||
};
|
||||
wchar_t *ptr = buf.data();
|
||||
for (size_t i = 0; i < n; i++, ptr += 2)
|
||||
{
|
||||
wmemcpy(ptr, s, 2);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Assume ch is a BMP character
|
||||
wxWCharBuffer buf(n);
|
||||
wmemset(buf.data(), (wchar_t)ch, n);
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
wxWxCharBuffer wxStringOperationsWchar::EncodeNChars(size_t n, const wxUniChar& ch)
|
||||
{
|
||||
wxWxCharBuffer buf(n);
|
||||
#if wxUSE_UNICODE_WCHAR
|
||||
wmemset(buf.data(), (wchar_t)ch, n);
|
||||
#else // ANSI
|
||||
memset(buf.data(), (unsigned char)ch, n);
|
||||
#endif
|
||||
return buf;
|
||||
}
|
||||
|
||||
#endif // wxUSE_UNICODE_UTF16
|
||||
|
||||
#endif // wxUSE_UNICODE_WCHAR || !wxUSE_UNICODE
|
||||
|
||||
#if wxUSE_UNICODE_UTF8
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user