common/common.c: handle utf16 in mp_parse_escape

Signed-off-by: wm4 <wm4@nowhere>
This commit is contained in:
kwkam 2016-02-06 14:57:00 +08:00 committed by wm4
parent 563b4785da
commit 3314483a02
1 changed files with 12 additions and 1 deletions

View File

@ -187,9 +187,20 @@ static bool mp_parse_escape(void *talloc_ctx, bstr *dst, bstr *code)
}
if (code->start[0] == 'u' && code->len >= 5) {
bstr num = bstr_splice(*code, 1, 5);
int c = bstrtoll(num, &num, 16);
uint32_t c = bstrtoll(num, &num, 16);
if (num.len)
return false;
if (c >= 0xd800 && c <= 0xdbff) {
if (code->len < 5 + 6 // udddd + \udddd
|| code->start[5] != '\\' || code->start[6] != 'u')
return false;
*code = bstr_cut(*code, 5 + 1);
bstr num2 = bstr_splice(*code, 1, 5);
uint32_t c2 = bstrtoll(num2, &num2, 16);
if (num2.len || c2 < 0xdc00 || c2 > 0xdfff)
return false;
c = ((c - 0xd800) << 10) + 0x10000 + (c2 - 0xdc00);
}
mp_append_utf8_bstr(talloc_ctx, dst, c);
*code = bstr_cut(*code, 5);
return true;