System/Libraries/Json: Keep escaped unicode in its original form, and let the program ingesting the JSON handle the UTF-8 conversion
This commit is contained in:
parent
cafa3158a3
commit
fcc95d971b
1 changed files with 24 additions and 5 deletions
|
@ -243,8 +243,14 @@ U0 @json_parse_object(@json_parser* parser, @json_object* obj)
|
||||||
while (1) {
|
while (1) {
|
||||||
switch (parser->stream[parser->pos]) {
|
switch (parser->stream[parser->pos]) {
|
||||||
case '\\':
|
case '\\':
|
||||||
if (parser->state == JSON_STATE_OBJECT_STRING)
|
// NOTE: We keep escaped unicode in its original form, and let the program ingesting the JSON handle the UTF-8 conversion.
|
||||||
FifoU8Ins(parser->consumed, @json_unescape_char(parser->stream[++parser->pos]));
|
if (parser->state == JSON_STATE_OBJECT_STRING) {
|
||||||
|
if (parser->stream[parser->pos + 1] == 'u') {
|
||||||
|
FifoU8Ins(parser->consumed, '\\');
|
||||||
|
} else {
|
||||||
|
FifoU8Ins(parser->consumed, @json_unescape_char(parser->stream[++parser->pos]));
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
switch (parser->state) {
|
switch (parser->state) {
|
||||||
|
@ -484,8 +490,14 @@ U0 @json_parse_array(@json_parser* parser, @json_array* arr)
|
||||||
}
|
}
|
||||||
switch (parser->stream[parser->pos]) {
|
switch (parser->stream[parser->pos]) {
|
||||||
case '\\':
|
case '\\':
|
||||||
if (parser->state == JSON_STATE_ARRAY_STRING)
|
// NOTE: We keep escaped unicode in its original form, and let the program ingesting the JSON handle the UTF-8 conversion.
|
||||||
FifoU8Ins(parser->consumed, @json_unescape_char(parser->stream[++parser->pos]));
|
if (parser->state == JSON_STATE_ARRAY_STRING) {
|
||||||
|
if (parser->stream[parser->pos + 1] == 'u') {
|
||||||
|
FifoU8Ins(parser->consumed, '\\');
|
||||||
|
} else {
|
||||||
|
FifoU8Ins(parser->consumed, @json_unescape_char(parser->stream[++parser->pos]));
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ']':
|
case ']':
|
||||||
switch (parser->state) {
|
switch (parser->state) {
|
||||||
|
@ -862,7 +874,14 @@ U0 @json_stringify_append_char_escape_quotes(U8* str, U8 char)
|
||||||
U0 @json_stringify_append_str(U8* str, U8* str2)
|
U0 @json_stringify_append_str(U8* str, U8* str2)
|
||||||
{
|
{
|
||||||
while (*str2) {
|
while (*str2) {
|
||||||
@json_stringify_append_char_escape_quotes(str, *str2);
|
// NOTE: We keep escaped unicode in its original form, and let the program ingesting the JSON handle the UTF-8 conversion.
|
||||||
|
if (*str2 == '\\' && *(str2 + 1) == 'u') {
|
||||||
|
str[StrLen(str)] = '\\';
|
||||||
|
str[StrLen(str)] = 'u';
|
||||||
|
str2++;
|
||||||
|
} else {
|
||||||
|
@json_stringify_append_char_escape_quotes(str, *str2);
|
||||||
|
}
|
||||||
str2++;
|
str2++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue