enhanced the json writer function

This commit is contained in:
hyung-hwan 2021-07-12 17:13:03 +00:00
parent 4cbcc38308
commit a7cbda7208

View File

@ -1120,8 +1120,12 @@ int mio_jsonwr_write (mio_jsonwr_t* jsonwr, mio_json_inst_t inst, int is_uchars,
!(sn->state == MIO_JSON_STATE_IN_OBJECT && sn->obj_awaiting_val)) goto incompatible_inst; !(sn->state == MIO_JSON_STATE_IN_OBJECT && sn->obj_awaiting_val)) goto incompatible_inst;
if (sn->index > 0) WRITE_COMMA (jsonwr); if (sn->index > 0) WRITE_COMMA (jsonwr);
sn->index++; sn->index++;
if ((jsonwr->flags & MIO_JSONWR_FLAG_PRETTY) &&
!(sn->state == MIO_JSON_STATE_IN_OBJECT && sn->obj_awaiting_val))
{
WRITE_INDENT (jsonwr);
}
sn->obj_awaiting_val = 0; sn->obj_awaiting_val = 0;
if (jsonwr->flags & MIO_JSONWR_FLAG_PRETTY) WRITE_INDENT (jsonwr);
WRITE_BYTES_NOESC (jsonwr, "[", 1); WRITE_BYTES_NOESC (jsonwr, "[", 1);
if (jsonwr->flags & MIO_JSONWR_FLAG_PRETTY) WRITE_LINE_BREAK (jsonwr); if (jsonwr->flags & MIO_JSONWR_FLAG_PRETTY) WRITE_LINE_BREAK (jsonwr);
if (push_write_state(jsonwr, MIO_JSON_STATE_IN_ARRAY) <= -1) return -1; if (push_write_state(jsonwr, MIO_JSON_STATE_IN_ARRAY) <= -1) return -1;
@ -1133,8 +1137,12 @@ int mio_jsonwr_write (mio_jsonwr_t* jsonwr, mio_json_inst_t inst, int is_uchars,
!(sn->state == MIO_JSON_STATE_IN_OBJECT && sn->obj_awaiting_val)) goto incompatible_inst; !(sn->state == MIO_JSON_STATE_IN_OBJECT && sn->obj_awaiting_val)) goto incompatible_inst;
if (sn->index > 0) WRITE_COMMA (jsonwr); if (sn->index > 0) WRITE_COMMA (jsonwr);
sn->index++; sn->index++;
if ((jsonwr->flags & MIO_JSONWR_FLAG_PRETTY) &&
!(sn->state == MIO_JSON_STATE_IN_OBJECT && sn->obj_awaiting_val))
{
WRITE_INDENT (jsonwr);
}
sn->obj_awaiting_val = 0; sn->obj_awaiting_val = 0;
if (jsonwr->flags & MIO_JSONWR_FLAG_PRETTY) WRITE_INDENT (jsonwr);
WRITE_BYTES_NOESC (jsonwr, "{", 1); WRITE_BYTES_NOESC (jsonwr, "{", 1);
if (jsonwr->flags & MIO_JSONWR_FLAG_PRETTY) WRITE_LINE_BREAK (jsonwr); if (jsonwr->flags & MIO_JSONWR_FLAG_PRETTY) WRITE_LINE_BREAK (jsonwr);
if (push_write_state (jsonwr, MIO_JSON_STATE_IN_OBJECT) <= -1) return -1; if (push_write_state (jsonwr, MIO_JSON_STATE_IN_OBJECT) <= -1) return -1;