summaryrefslogtreecommitdiffhomepage
path: root/src/unicode
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2017-11-13 08:45:19 +0000
committermidipix <writeonce@midipix.org>2017-11-13 07:42:20 -0500
commit880eca4cffd67286ce055263152b69d1eab5f7fb (patch)
tree1f69935cb958fe2dcdbddec31b8e93c80105ef24 /src/unicode
parent13e6f2c0fd263fb501a74cf3d53889661db94ee0 (diff)
downloadntapi-880eca4cffd67286ce055263152b69d1eab5f7fb.tar.bz2
ntapi-880eca4cffd67286ce055263152b69d1eab5f7fb.tar.xz
unicode: __utf8_to_utf16_handler_4bytes(): fix conversion logic.
Diffstat (limited to 'src/unicode')
-rw-r--r--src/unicode/ntapi_uc_unicode_conversion_from_utf8.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/unicode/ntapi_uc_unicode_conversion_from_utf8.c b/src/unicode/ntapi_uc_unicode_conversion_from_utf8.c
index ab66a77..2741503 100644
--- a/src/unicode/ntapi_uc_unicode_conversion_from_utf8.c
+++ b/src/unicode/ntapi_uc_unicode_conversion_from_utf8.c
@@ -135,10 +135,14 @@ static int32_t __fastcall __utf8_to_utf16_handler_4bytes(nt_utf8_callback_args *
wchar16_t * dst_lead;
wchar16_t * dst_trail;
- wchar16_t u;
+ wchar16_t wwww;
+ wchar16_t lead;
+ wchar16_t trail;
unsigned char ulow;
unsigned char uhigh;
+ unsigned char yy;
unsigned char yyyy;
+ unsigned char zzzz;
dst_lead = dst_trail = (wchar16_t *)args->dst;
dst_trail++;
@@ -149,27 +153,39 @@ static int32_t __fastcall __utf8_to_utf16_handler_4bytes(nt_utf8_callback_args *
src_low = src_high = (__two_bytes *)args->src;
src_high++;
- /* u */
+ /* uuuuu */
ulow = src_low->low ^ 0xF0;
uhigh = src_low->high ^ 0x80;
ulow <<= 2;
uhigh >>= 4;
- u = ulow | uhigh;
+ /* wwww */
+ wwww = (ulow | uhigh) - 1;
+ wwww <<= 6;
/* 110110ww wwzzzzyy */
- *dst_lead = 0xD800;
- *dst_lead |= ((u-1) << 6);
- *dst_lead |= ((src_low->high ^ 0x80) << 2);
- *dst_lead |= ((src_high->low ^ 0x80) >> 4);
+ yy = src_high->low ^ 0x80;
+ yy >>= 4;
+
+ zzzz = src_low->high;
+ zzzz <<= 4;
+ zzzz >>= 2;
+
+ lead = 0xD800;
+ lead |= wwww;
+ lead |= zzzz;
+ lead |= yy;
/* 110111yy yyxxxxxx */
- yyyy = (src_high->low << 4);
- *dst_trail = yyyy;
- *dst_trail <<= 2;
- *dst_trail |= (src_high->high ^ 0x80);
- *dst_trail |= 0xDC00;
+ yyyy = src_high->low << 4;
+ trail = yyyy << 2;
+ trail |= src_high->high ^ 0x80;
+ trail |= 0xDC00;
+
+ /* write */
+ *dst_lead = lead;
+ *dst_trail = trail;
/* advance source and destination buffer */
args->src += 4;