converted a unicode character to utf8 stream in the bch mode when handling \u or \U in json.c

This commit is contained in:
hyung-hwan 2018-04-26 09:18:49 +00:00
parent baae283222
commit b0d302baec

View File

@ -60,13 +60,17 @@ struct hcl_json_state_node_t
{ {
int escaped; int escaped;
int digit_count; int digit_count;
hcl_ooch_t acc; /* acc is always of unicode type to handle \u and \U.
* in the bch mode, it will get converted to a utf8 stream. */
hcl_uch_t acc;
} sv; } sv;
struct struct
{ {
int escaped; int escaped;
int digit_count; int digit_count;
hcl_ooch_t acc; /* for a character, no way to support the unicode character
* in the bch mode */
hcl_ooch_t acc;
} cv; } cv;
struct struct
{ {
@ -284,8 +288,7 @@ static int invoke_data_inst (hcl_json_t* json, hcl_json_inst_t inst)
static int handle_string_value_char (hcl_json_t* json, hcl_ooci_t c) static int handle_string_value_char (hcl_json_t* json, hcl_ooci_t c)
{ {
int ret = 1; int ret = 1;
if (json->state_stack->u.sv.escaped == 3) if (json->state_stack->u.sv.escaped == 3)
{ {
if (c >= '0' && c <= '7') if (c >= '0' && c <= '7')
@ -324,7 +327,29 @@ static int handle_string_value_char (hcl_json_t* json, hcl_ooci_t c)
{ {
ret = 0; ret = 0;
add_sv_acc: add_sv_acc:
#if defined(HCL_OOCH_IS_BCH)
/* convert the character to utf8 */
{
hcl_bch_t bcsbuf[HCL_BCSIZE_MAX];
hcl_oow_t ucslen = 1, bcslen;
if (hcl_conv_uchars_to_bchars_with_cmgr(&json->state_stack->u.sv.acc, &ucslen, bcsbuf, &bcslen, hcl_json_getcmgr(json)) <= -1)
{
hcl_json_seterrbfmt (json, HCL_EECERR, "unable to convert %jc", acc);
return -1;
}
else
{
hcl_oow_t i;
for (i = 0; i < bcslen; i++)
{
if (add_char_to_token(json, bcsbuf[i]) <= -1) return -1;
}
}
}
#else
if (add_char_to_token(json, json->state_stack->u.sv.acc) <= -1) return -1; if (add_char_to_token(json, json->state_stack->u.sv.acc) <= -1) return -1;
#endif
json->state_stack->u.sv.escaped = 0; json->state_stack->u.sv.escaped = 0;
} }
} }