diff options
Diffstat (limited to 'src/unicode/ntapi_uc_unicode_conversion_from_utf8.c')
-rw-r--r-- | src/unicode/ntapi_uc_unicode_conversion_from_utf8.c | 40 |
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; |