added the rctx field to mio_json_t
changed mio_json_instcb_t to get passed the content pointer
This commit is contained in:
parent
cfd80f778c
commit
c2c3d00ff2
@ -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, const mio_oocs_t* str)
|
static int on_json_inst (mio_json_t* json, mio_json_inst_t inst, mio_oow_t level, 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;
|
||||||
@ -114,7 +114,7 @@ int main (int argc, char* argv[])
|
|||||||
|
|
||||||
json = mio_json_open(mio, 0);
|
json = mio_json_open(mio, 0);
|
||||||
|
|
||||||
mio_json_setinstcb (json, on_json_inst);
|
mio_json_setinstcb (json, on_json_inst, MIO_NULL);
|
||||||
|
|
||||||
|
|
||||||
rem = 0;
|
rem = 0;
|
||||||
|
@ -155,7 +155,7 @@ static int invoke_data_inst (mio_json_t* json, mio_json_inst_t inst)
|
|||||||
inst = MIO_JSON_INST_KEY;
|
inst = MIO_JSON_INST_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return json->instcb(json, inst, json->state_stack->level, &json->tok);
|
return json->instcb(json, inst, json->state_stack->level, &json->tok, json->rctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_string_value_char (mio_json_t* json, mio_ooci_t c)
|
static int handle_string_value_char (mio_json_t* json, mio_ooci_t c)
|
||||||
@ -333,7 +333,7 @@ printf ("HANDLE START CHAR [%c]\n", c);
|
|||||||
{
|
{
|
||||||
if (push_read_state(json, MIO_JSON_STATE_IN_ARRAY) <= -1) return -1;
|
if (push_read_state(json, MIO_JSON_STATE_IN_ARRAY) <= -1) return -1;
|
||||||
json->state_stack->u.ia.got_value = 0;
|
json->state_stack->u.ia.got_value = 0;
|
||||||
if (json->instcb(json, MIO_JSON_INST_START_ARRAY, json->state_stack->level, MIO_NULL) <= -1) return -1;
|
if (json->instcb(json, MIO_JSON_INST_START_ARRAY, json->state_stack->level, MIO_NULL, json->rctx) <= -1) return -1;
|
||||||
json->state_stack->level++;
|
json->state_stack->level++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -341,7 +341,7 @@ printf ("HANDLE START CHAR [%c]\n", c);
|
|||||||
{
|
{
|
||||||
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;
|
||||||
if (json->instcb(json, MIO_JSON_INST_START_DIC, json->state_stack->level, MIO_NULL) <= -1) return -1;
|
if (json->instcb(json, MIO_JSON_INST_START_DIC, json->state_stack->level, MIO_NULL, json->rctx) <= -1) return -1;
|
||||||
json->state_stack->level++;
|
json->state_stack->level++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -364,7 +364,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, MIO_NULL) <= -1) return -1;
|
if (json->instcb(json, MIO_JSON_INST_END_ARRAY, json->state_stack->level - 1, MIO_NULL, json->rctx) <= -1) return -1;
|
||||||
pop_read_state (json);
|
pop_read_state (json);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -416,7 +416,7 @@ static int handle_char_in_array (mio_json_t* json, mio_ooci_t c)
|
|||||||
{
|
{
|
||||||
if (push_read_state(json, MIO_JSON_STATE_IN_ARRAY) <= -1) return -1;
|
if (push_read_state(json, MIO_JSON_STATE_IN_ARRAY) <= -1) return -1;
|
||||||
json->state_stack->u.ia.got_value = 0;
|
json->state_stack->u.ia.got_value = 0;
|
||||||
if (json->instcb(json, MIO_JSON_INST_START_ARRAY, json->state_stack->level, MIO_NULL) <= -1) return -1;
|
if (json->instcb(json, MIO_JSON_INST_START_ARRAY, json->state_stack->level, MIO_NULL, json->rctx) <= -1) return -1;
|
||||||
json->state_stack->level++;
|
json->state_stack->level++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -424,7 +424,7 @@ static int handle_char_in_array (mio_json_t* json, mio_ooci_t c)
|
|||||||
{
|
{
|
||||||
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;
|
||||||
if (json->instcb(json, MIO_JSON_INST_START_DIC, json->state_stack->level, MIO_NULL) <= -1) return -1;
|
if (json->instcb(json, MIO_JSON_INST_START_DIC, json->state_stack->level, MIO_NULL, json->rctx) <= -1) return -1;
|
||||||
json->state_stack->level++;
|
json->state_stack->level++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -440,7 +440,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, MIO_NULL) <= -1) return -1;
|
if (json->instcb(json, MIO_JSON_INST_END_DIC, json->state_stack->level - 1, MIO_NULL, json->rctx) <= -1) return -1;
|
||||||
pop_read_state (json);
|
pop_read_state (json);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -508,7 +508,7 @@ static int handle_char_in_dic (mio_json_t* json, mio_ooci_t c)
|
|||||||
if (push_read_state(json, MIO_JSON_STATE_IN_ARRAY) <= -1) return -1;
|
if (push_read_state(json, MIO_JSON_STATE_IN_ARRAY) <= -1) return -1;
|
||||||
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 (json->instcb(json, MIO_JSON_INST_START_ARRAY, json->state_stack->level, MIO_NULL) <= -1) return -1;
|
if (json->instcb(json, MIO_JSON_INST_START_ARRAY, json->state_stack->level, MIO_NULL, json->rctx) <= -1) return -1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (c == '{')
|
else if (c == '{')
|
||||||
@ -516,7 +516,7 @@ static int handle_char_in_dic (mio_json_t* json, mio_ooci_t c)
|
|||||||
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 (json->instcb(json, MIO_JSON_INST_START_DIC, json->state_stack->level, MIO_NULL) <= -1) return -1;
|
if (json->instcb(json, MIO_JSON_INST_START_DIC, json->state_stack->level, MIO_NULL, json->rctx) <= -1) return -1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -709,9 +709,10 @@ void mio_json_fini (mio_json_t* json)
|
|||||||
}
|
}
|
||||||
/* ========================================================================= */
|
/* ========================================================================= */
|
||||||
|
|
||||||
void mio_json_setinstcb (mio_json_t* json, mio_json_instcb_t instcb)
|
void mio_json_setinstcb (mio_json_t* json, mio_json_instcb_t instcb, void* ctx)
|
||||||
{
|
{
|
||||||
json->instcb = instcb;
|
json->instcb = instcb;
|
||||||
|
json->rctx = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
mio_json_state_t mio_json_getstate (mio_json_t* json)
|
mio_json_state_t mio_json_getstate (mio_json_t* json)
|
||||||
|
@ -70,7 +70,8 @@ typedef int (*mio_json_instcb_t) (
|
|||||||
mio_json_t* json,
|
mio_json_t* json,
|
||||||
mio_json_inst_t inst,
|
mio_json_inst_t inst,
|
||||||
mio_oow_t level,
|
mio_oow_t level,
|
||||||
const mio_oocs_t* str
|
const mio_oocs_t* str,
|
||||||
|
void* ctx
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -120,6 +121,7 @@ struct mio_json_t
|
|||||||
{
|
{
|
||||||
mio_t* mio;
|
mio_t* mio;
|
||||||
mio_json_instcb_t instcb;
|
mio_json_instcb_t instcb;
|
||||||
|
void* rctx;
|
||||||
|
|
||||||
mio_json_state_node_t state_top;
|
mio_json_state_node_t state_top;
|
||||||
mio_json_state_node_t* state_stack;
|
mio_json_state_node_t* state_stack;
|
||||||
@ -199,7 +201,8 @@ static MIO_INLINE void* mio_json_getxtn (mio_json_t* json) { return (void*)(json
|
|||||||
|
|
||||||
MIO_EXPORT void mio_json_setinstcb (
|
MIO_EXPORT void mio_json_setinstcb (
|
||||||
mio_json_t* json,
|
mio_json_t* json,
|
||||||
mio_json_instcb_t instcb
|
mio_json_instcb_t instcb,
|
||||||
|
void* ctx
|
||||||
);
|
);
|
||||||
|
|
||||||
MIO_EXPORT mio_json_state_t mio_json_getstate (
|
MIO_EXPORT mio_json_state_t mio_json_getstate (
|
||||||
|
Loading…
Reference in New Issue
Block a user