added MIO_JSON_OPTIONAL_COMMA

This commit is contained in:
hyung-hwan 2021-07-14 05:29:17 +00:00
parent 3e0654e131
commit 33afbfc419
2 changed files with 18 additions and 4 deletions

View File

@ -120,6 +120,7 @@ int main (int argc, char* argv[])
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
if (strcmp(argv[i], "--permit-word-key") == 0) o |= MIO_JSON_PERMIT_WORD_KEY; if (strcmp(argv[i], "--permit-word-key") == 0) o |= MIO_JSON_PERMIT_WORD_KEY;
if (strcmp(argv[i], "--optional-comma") == 0) o |= MIO_JSON_OPTIONAL_COMMA;
} }
mio = mio_open(MIO_NULL, 0, MIO_NULL, 512, MIO_NULL); mio = mio_open(MIO_NULL, 0, MIO_NULL, 512, MIO_NULL);

View File

@ -502,10 +502,17 @@ static int handle_char_in_array (mio_json_t* json, mio_ooci_t c)
else else
{ {
if (json->state_stack->u.ia.got_value) if (json->state_stack->u.ia.got_value)
{
if (json->option & MIO_JSON_OPTIONAL_COMMA)
{
json->state_stack->u.ia.got_value = 0;
}
else
{ {
mio_seterrbfmt (json->mio, MIO_EINVAL, "comma required in array - %jc", (mio_ooch_t)c); mio_seterrbfmt (json->mio, MIO_EINVAL, "comma required in array - %jc", (mio_ooch_t)c);
return -1; return -1;
} }
}
if (c == '\"') if (c == '\"')
{ {
@ -588,9 +595,15 @@ static int handle_char_in_object (mio_json_t* json, mio_ooci_t c)
return -1; return -1;
} }
else if (json->state_stack->u.io.state == 3) else if (json->state_stack->u.io.state == 3)
{
if (json->option & MIO_JSON_OPTIONAL_COMMA)
{
json->state_stack->u.io.state = 0;
}
else
{ {
mio_seterrbfmt (json->mio, MIO_EINVAL, "comma required in object - %jc", (mio_ooch_t)c); mio_seterrbfmt (json->mio, MIO_EINVAL, "comma required in object - %jc", (mio_ooch_t)c);
return -1; }
} }
if (c == '\"') if (c == '\"')