Use the added wxUniChar functions in the existing code

This commit is contained in:
ARATA Mizuki
2017-05-01 14:44:45 +09:00
parent 90c990cf83
commit 8a29c5c09f
2 changed files with 12 additions and 12 deletions

View File

@@ -80,27 +80,27 @@ static bool NotAllNULs(const char *p, size_t n)
static size_t encode_utf16(wxUint32 input, wxUint16 *output) static size_t encode_utf16(wxUint32 input, wxUint16 *output)
{ {
if (input <= 0xffff) if (wxUniChar::IsBMP(input))
{ {
if (output) if (output)
*output = (wxUint16) input; *output = (wxUint16) input;
return 1; return 1;
} }
else if (input >= 0x110000) else if (wxUniChar::IsSupplementary(input))
{
return wxCONV_FAILED;
}
else
{ {
if (output) if (output)
{ {
*output++ = (wxUint16) ((input >> 10) + 0xd7c0); *output++ = wxUniChar::HighSurrogate(input);
*output = (wxUint16) ((input & 0x3ff) + 0xdc00); *output = wxUniChar::LowSurrogate(input);
} }
return 2; return 2;
} }
else
{
return wxCONV_FAILED;
}
} }
static size_t decode_utf16(const wxUint16* input, wxUint32& output) static size_t decode_utf16(const wxUint16* input, wxUint32& output)

View File

@@ -502,7 +502,7 @@ wxScopedU16CharBuffer wxUString::utf16_str() const
// TODO: error range checks // TODO: error range checks
if (code < 0x10000) if (wxUniChar::IsBMP(code))
utf16_length++; utf16_length++;
else else
utf16_length += 2; utf16_length += 2;
@@ -520,15 +520,15 @@ wxScopedU16CharBuffer wxUString::utf16_str() const
// TODO: error range checks // TODO: error range checks
if (code < 0x10000) if (wxUniChar::IsBMP(code))
{ {
out[0] = code; out[0] = code;
out++; out++;
} }
else else
{ {
out[0] = (code - 0x10000) / 0x400 + 0xd800; out[0] = wxUniChar::HighSurrogate(code);
out[1] = (code - 0x10000) % 0x400 + 0xdc00; out[1] = wxUniChar::LowSurrogate(code);
out += 2; out += 2;
} }
} }