From 8e07fb8117b0e3013f2072d743ab484c8d6a0c1a Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Tue, 2 Aug 2016 18:24:14 +1000 Subject: Fix UTF-16 encode, pass UTF-16 to Windows character drawing (unfortunately still no nice speaker icon) --- src/lib/util/unicode.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/lib/util/unicode.cpp') diff --git a/src/lib/util/unicode.cpp b/src/lib/util/unicode.cpp index 83e906e112b..535207e2431 100644 --- a/src/lib/util/unicode.cpp +++ b/src/lib/util/unicode.cpp @@ -128,21 +128,21 @@ int uchar_from_utf16(unicode_char *uchar, const utf16_char *utf16char, size_t co // validate parameters if (utf16char == nullptr || count == 0) - return 0; - - // handle the two-byte case + { + rc = 0; + } if (utf16char[0] >= 0xd800 && utf16char[0] <= 0xdbff) { + // handle the two-byte case if (count > 1 && utf16char[1] >= 0xdc00 && utf16char[1] <= 0xdfff) { *uchar = 0x10000 + ((utf16char[0] & 0x3ff) * 0x400) + (utf16char[1] & 0x3ff); rc = 2; } } - - // handle the one-byte case else if (utf16char[0] < 0xdc00 || utf16char[0] > 0xdfff) { + // handle the one-byte case *uchar = utf16char[0]; rc = 1; } @@ -272,26 +272,28 @@ int utf16_from_uchar(utf16_char *utf16string, size_t count, unicode_char uchar) if (!uchar_isvalid(uchar)) return -1; - // single word case if (uchar < 0x10000) { + // single word case if (count < 1) return -1; utf16string[0] = (utf16_char) uchar; rc = 1; } - - // double word case else if (uchar < 0x100000) { + // double word case if (count < 2) return -1; + uchar -= 0x10000; utf16string[0] = ((uchar >> 10) & 0x03ff) | 0xd800; utf16string[1] = ((uchar >> 0) & 0x03ff) | 0xdc00; rc = 2; } else + { return -1; + } return rc; } -- cgit v1.2.3-70-g09d2