fix json parser key adding

This commit is contained in:
Олег Бородин
2023-09-21 12:00:48 +02:00
parent 5edc2ec41e
commit 375930eaac
7 changed files with 225 additions and 190 deletions

View File

@@ -56,6 +56,31 @@ static bool jblock_keyexists(jblock_t* jb, char* key) {
return false;
}
static bool jblock_arrexists(jblock_t* jb, char* key, int type) {
for (int i = 0; i < jb->kvsize; i++) {
if (strcmp(key, jb->kvarr[i].key) == 0 && jb->kvarr[i].type == type) {
return true;
}
}
return false;
}
int jblock_addarrint(jblock_t* jb, char* key, int64_t val) {
if (jblock_keyexists(jb, key)) {
}
if (jblock_checkalloc(jb) == NULL) {
return -1;
}
jb->kvarr[jb->kvsize].key = strcopy(key);
jb->kvarr[jb->kvsize].num = val;
jb->kvarr[jb->kvsize].type = JKVTYPE_INTARR;
return ++jb->kvsize;
}
int jblock_addint(jblock_t* jb, char* key, int64_t val) {
if (jblock_keyexists(jb, key)) {

View File

@@ -41,7 +41,7 @@ int jparser_parse(jparser_t * parser) {
char* key = "";
while ((type = jlexer_gettoken(lex, token)) != JLEXTOK_END) {
printf("pos %d tok 0x%02x: %s\n", pos, type, token);
//printf("pos %d tok 0x%02x: %s\n", pos, type, token);
switch (pos) {
// POS 0
case 0:{
@@ -111,7 +111,8 @@ int jparser_parse(jparser_t * parser) {
jkval_t* kv = &(parser->kvalarr[parser->kvalsize]);
kv->key = key;
kv->key = strcopy(key);
log_debug("parser added key %s", kv->key);
if (type == JLEXTOK_NUMB) {
kv->type = JVALTYPE_NUM;
char* eptr = NULL;
@@ -161,6 +162,7 @@ int jparser_bind(jparser_t* parser, int type, char* key, void* ref) {
for (int i = 0; i < parser->kvalsize; i++) {
jkval_t* kv = &(parser->kvalarr[i]);
log_debug("find equal keys: kv->key = %s, key = %s", kv->key, key);
if (strcmp(kv->key, key) == 0) {
if (kv->type == JVALTYPE_STR) {
*(char**)(ref) = strcopy(kv->str);