1
0
Fork 0

Standardize how unicode is processed (fixes #8768) (#8770)

Co-authored-by: Konstantin Đorđević <vomindoraan@gmail.com>
This commit is contained in:
Jason Laqua 2020-06-18 02:07:34 -05:00 committed by GitHub
parent aae1814319
commit f7eb030e91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 96 deletions

View file

@ -171,6 +171,25 @@ void register_hex32(uint32_t hex) {
}
}
void register_unicode(uint32_t code_point) {
if (code_point > 0x10FFFF || (code_point > 0xFFFF && unicode_config.input_mode == UC_WIN)) {
// Code point out of range, do nothing
return;
}
unicode_input_start();
if (code_point > 0xFFFF && unicode_config.input_mode == UC_MAC) {
// Convert code point to UTF-16 surrogate pair on macOS
code_point -= 0x10000;
uint32_t lo = code_point & 0x3FF, hi = (code_point & 0xFFC00) >> 10;
register_hex32(hi + 0xD800);
register_hex32(lo + 0xDC00);
} else {
register_hex32(code_point);
}
unicode_input_finish();
}
// clang-format off
void send_unicode_hex_string(const char *str) {
@ -236,14 +255,12 @@ void send_unicode_string(const char *str) {
return;
}
int32_t code_point = 0;
while (*str) {
int32_t code_point = 0;
str = decode_utf8(str, &code_point);
if (code_point >= 0) {
unicode_input_start();
register_hex32(code_point);
unicode_input_finish();
register_unicode(code_point);
}
}
}