From 378f148f73f1365689b50c1c4cb8ce6e9ae31bdf Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 6 Jun 2020 19:45:11 +0000 Subject: [PATCH] added the container_state parameter to the mio_json_instcb_t callback --- mio/bin/t03.c | 2 +- mio/lib/json.c | 10 +++++----- mio/lib/mio-json.h | 1 + mio/lib/mio-utl.h | 48 ++++++++++++++++++++++++++++++---------------- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/mio/bin/t03.c b/mio/bin/t03.c index 636b7c0..0f6e347 100644 --- a/mio/bin/t03.c +++ b/mio/bin/t03.c @@ -30,7 +30,7 @@ #include #include -static int on_json_inst (mio_json_t* json, mio_json_inst_t inst, mio_oow_t level, mio_oow_t index, const mio_oocs_t* str, void* ctx) +static int on_json_inst (mio_json_t* json, mio_json_inst_t inst, mio_oow_t level, mio_oow_t index, mio_json_state_t container_state, const mio_oocs_t* str, void* ctx) { mio_t* mio = mio_json_getmio(json); mio_oow_t i; diff --git a/mio/lib/json.c b/mio/lib/json.c index 2b9d6cd..4f0618e 100644 --- a/mio/lib/json.c +++ b/mio/lib/json.c @@ -179,18 +179,18 @@ static int invoke_data_inst (mio_json_t* json, mio_json_inst_t inst) json->state_stack->u.ia.got_value = 0; json->state_stack->level++; if (ss->state != MIO_JSON_STATE_IN_DIC || ss->u.id.state == 1) ss->index++; - return json->instcb(json, inst, (is_dic_val? 0: json->state_stack->level - 1), ss->index - 1, MIO_NULL, json->rctx); + return json->instcb(json, inst, (is_dic_val? 0: json->state_stack->level - 1), ss->index - 1, ss->state, MIO_NULL, json->rctx); case MIO_JSON_INST_START_DIC: if (push_read_state(json, MIO_JSON_STATE_IN_DIC) <= -1) return -1; json->state_stack->u.id.state = 0; json->state_stack->level++; if (ss->state != MIO_JSON_STATE_IN_DIC || ss->u.id.state == 1) ss->index++; - return json->instcb(json, inst, (is_dic_val? 0: json->state_stack->level - 1), ss->index - 1, MIO_NULL, json->rctx); + return json->instcb(json, inst, (is_dic_val? 0: json->state_stack->level - 1), ss->index - 1, ss->state, MIO_NULL, json->rctx); default: if (ss->state != MIO_JSON_STATE_IN_DIC || ss->u.id.state == 1) ss->index++; - return json->instcb(json, inst, (is_dic_val? 0: json->state_stack->level), ss->index - 1, &json->tok, json->rctx); + return json->instcb(json, inst, (is_dic_val? 0: json->state_stack->level), ss->index - 1, ss->state, &json->tok, json->rctx); } } @@ -396,7 +396,7 @@ static int handle_char_in_array (mio_json_t* json, mio_ooci_t c) { if (c == ']') { - if (json->instcb(json, MIO_JSON_INST_END_ARRAY, json->state_stack->level - 1, json->state_stack->index, MIO_NULL, json->rctx) <= -1) return -1; + if (json->instcb(json, MIO_JSON_INST_END_ARRAY, json->state_stack->level - 1, json->state_stack->index, json->state_stack->next->state, MIO_NULL, json->rctx) <= -1) return -1; pop_read_state (json); return 1; } @@ -466,7 +466,7 @@ static int handle_char_in_dic (mio_json_t* json, mio_ooci_t c) { if (c == '}') { - if (json->instcb(json, MIO_JSON_INST_END_DIC, json->state_stack->level - 1, json->state_stack->index, MIO_NULL, json->rctx) <= -1) return -1; + if (json->instcb(json, MIO_JSON_INST_END_DIC, json->state_stack->level - 1, json->state_stack->index, json->state_stack->next->state, MIO_NULL, json->rctx) <= -1) return -1; pop_read_state (json); return 1; } diff --git a/mio/lib/mio-json.h b/mio/lib/mio-json.h index a8a6e4f..305c8d6 100644 --- a/mio/lib/mio-json.h +++ b/mio/lib/mio-json.h @@ -71,6 +71,7 @@ typedef int (*mio_json_instcb_t) ( mio_json_inst_t inst, mio_oow_t level, mio_oow_t index, + mio_json_state_t container_state, const mio_oocs_t* str, void* ctx ); diff --git a/mio/lib/mio-utl.h b/mio/lib/mio-utl.h index b39fee0..d09ec00 100644 --- a/mio/lib/mio-utl.h +++ b/mio/lib/mio-utl.h @@ -548,26 +548,35 @@ MIO_EXPORT mio_oow_t mio_byte_to_bcstr ( ); /* ------------------------------------------------------------------------- */ +#define MIO_OOCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) (((!!(ltrim)) << 2) | ((!!(rtrim)) << 4) | ((base) << 8)) +#define MIO_OOCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) ((option) & 4) +#define MIO_OOCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) ((option) & 8) +#define MIO_OOCHARS_TO_INTMAX_GET_OPTION_BASE(option) ((option) >> 8) -#define MIO_UCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) (((!!(ltrim)) << 2) | ((!!(rtrim)) << 4) | ((base) << 8)) -#define MIO_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) ((option) & 4) -#define MIO_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) ((option) & 8) -#define MIO_UCHARS_TO_INTMAX_GET_OPTION_BASE(option) ((option) >> 8) +#define MIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base) (((!!(ltrim)) << 2) | ((!!(rtrim)) << 4) | ((base) << 8)) +#define MIO_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) ((option) & 4) +#define MIO_OOCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) ((option) & 8) +#define MIO_OOCHARS_TO_UINTMAX_GET_OPTION_BASE(option) ((option) >> 8) -#define MIO_BCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) MIO_UCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) -#define MIO_BCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) MIO_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) -#define MIO_BCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) MIO_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) -#define MIO_BCHARS_TO_INTMAX_GET_OPTION_BASE(option) MIO_UCHARS_TO_INTMAX_GET_OPTION_BASE(option) +#define MIO_UCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) MIO_OOCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) +#define MIO_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) +#define MIO_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) +#define MIO_UCHARS_TO_INTMAX_GET_OPTION_BASE(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_BASE(option) -#define MIO_UCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base) MIO_UCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) -#define MIO_UCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) MIO_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) -#define MIO_UCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) MIO_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) -#define MIO_UCHARS_TO_UINTMAX_GET_OPTION_BASE(option) MIO_UCHARS_TO_INTMAX_GET_OPTION_BASE(option) +#define MIO_BCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) MIO_OOCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) +#define MIO_BCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) +#define MIO_BCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) +#define MIO_BCHARS_TO_INTMAX_GET_OPTION_BASE(option) MIO_OOCHARS_TO_INTMAX_GET_OPTION_BASE(option) -#define MIO_BCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base) MIO_UCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) -#define MIO_BCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) MIO_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) -#define MIO_BCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) MIO_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) -#define MIO_BCHARS_TO_UINTMAX_GET_OPTION_BASE(option) MIO_UCHARS_TO_INTMAX_GET_OPTION_BASE(option) +#define MIO_UCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base) MIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base) +#define MIO_UCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) +#define MIO_UCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) +#define MIO_UCHARS_TO_UINTMAX_GET_OPTION_BASE(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_BASE(option) + +#define MIO_BCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base) MIO_OOCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base) +#define MIO_BCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) +#define MIO_BCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) +#define MIO_BCHARS_TO_UINTMAX_GET_OPTION_BASE(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_BASE(option) MIO_EXPORT mio_intmax_t mio_uchars_to_intmax ( const mio_uch_t* str, @@ -600,6 +609,13 @@ MIO_EXPORT mio_uintmax_t mio_bchars_to_uintmax ( const mio_bch_t** endptr, int* is_sober ); +#if defined(MIO_OOCH_IS_UCH) +# define mio_oochars_to_intmax mio_uchars_to_intmax +# define mio_oochars_to_uintmax mio_uchars_to_uintmax +#else +# define mio_oochars_to_intmax mio_bchars_to_intmax +# define mio_oochars_to_uintmax mio_bchars_to_uintmax +#endif /* ------------------------------------------------------------------------- */