added the container_state parameter to the mio_json_instcb_t callback
This commit is contained in:
parent
2174c1bd9b
commit
378f148f73
@ -30,7 +30,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
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_t* mio = mio_json_getmio(json);
|
||||||
mio_oow_t i;
|
mio_oow_t i;
|
||||||
|
@ -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->u.ia.got_value = 0;
|
||||||
json->state_stack->level++;
|
json->state_stack->level++;
|
||||||
if (ss->state != MIO_JSON_STATE_IN_DIC || ss->u.id.state == 1) ss->index++;
|
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:
|
case MIO_JSON_INST_START_DIC:
|
||||||
if (push_read_state(json, MIO_JSON_STATE_IN_DIC) <= -1) return -1;
|
if (push_read_state(json, MIO_JSON_STATE_IN_DIC) <= -1) return -1;
|
||||||
json->state_stack->u.id.state = 0;
|
json->state_stack->u.id.state = 0;
|
||||||
json->state_stack->level++;
|
json->state_stack->level++;
|
||||||
if (ss->state != MIO_JSON_STATE_IN_DIC || ss->u.id.state == 1) ss->index++;
|
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:
|
default:
|
||||||
if (ss->state != MIO_JSON_STATE_IN_DIC || ss->u.id.state == 1) ss->index++;
|
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 (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);
|
pop_read_state (json);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -466,7 +466,7 @@ static int handle_char_in_dic (mio_json_t* json, mio_ooci_t c)
|
|||||||
{
|
{
|
||||||
if (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);
|
pop_read_state (json);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -71,6 +71,7 @@ typedef int (*mio_json_instcb_t) (
|
|||||||
mio_json_inst_t inst,
|
mio_json_inst_t inst,
|
||||||
mio_oow_t level,
|
mio_oow_t level,
|
||||||
mio_oow_t index,
|
mio_oow_t index,
|
||||||
|
mio_json_state_t container_state,
|
||||||
const mio_oocs_t* str,
|
const mio_oocs_t* str,
|
||||||
void* ctx
|
void* ctx
|
||||||
);
|
);
|
||||||
|
@ -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_OOCHARS_TO_UINTMAX_MAKE_OPTION(ltrim,rtrim,base) (((!!(ltrim)) << 2) | ((!!(rtrim)) << 4) | ((base) << 8))
|
||||||
#define MIO_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) ((option) & 4)
|
#define MIO_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) ((option) & 4)
|
||||||
#define MIO_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) ((option) & 8)
|
#define MIO_OOCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) ((option) & 8)
|
||||||
#define MIO_UCHARS_TO_INTMAX_GET_OPTION_BASE(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_UCHARS_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_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option)
|
#define MIO_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) MIO_OOCHARS_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_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) MIO_OOCHARS_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_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_BCHARS_TO_INTMAX_MAKE_OPTION(ltrim,rtrim,base) MIO_OOCHARS_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_BCHARS_TO_INTMAX_GET_OPTION_LTRIM(option) MIO_OOCHARS_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_BCHARS_TO_INTMAX_GET_OPTION_RTRIM(option) MIO_OOCHARS_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_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_UCHARS_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_UCHARS_TO_INTMAX_GET_OPTION_LTRIM(option)
|
#define MIO_UCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option) MIO_OOCHARS_TO_UINTMAX_GET_OPTION_LTRIM(option)
|
||||||
#define MIO_BCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) MIO_UCHARS_TO_INTMAX_GET_OPTION_RTRIM(option)
|
#define MIO_UCHARS_TO_UINTMAX_GET_OPTION_RTRIM(option) MIO_OOCHARS_TO_UINTMAX_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_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 (
|
MIO_EXPORT mio_intmax_t mio_uchars_to_intmax (
|
||||||
const mio_uch_t* str,
|
const mio_uch_t* str,
|
||||||
@ -600,6 +609,13 @@ MIO_EXPORT mio_uintmax_t mio_bchars_to_uintmax (
|
|||||||
const mio_bch_t** endptr,
|
const mio_bch_t** endptr,
|
||||||
int* is_sober
|
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
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------- */
|
/* ------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user