added bool type parsing
This commit is contained in:
@@ -41,7 +41,7 @@ int jparser_parse(jparser_t * parser) {
|
||||
char* key = "";
|
||||
|
||||
while ((type = jlexer_gettoken(lex, token)) != JLEXTOK_END) {
|
||||
//log_debug("pos %d tok 0x%02x: %s\n", pos, type, token);
|
||||
log_debug("pos %d tok 0x%02x: %s\n", pos, type, token);
|
||||
switch (pos) {
|
||||
// POS 0
|
||||
case 0:{
|
||||
@@ -103,29 +103,59 @@ int jparser_parse(jparser_t * parser) {
|
||||
pos = 1;
|
||||
continue;
|
||||
}
|
||||
if (type != JLEXTOK_WORD && type != JLEXTOK_NUMB) {
|
||||
log_error("Wrong value token: %s", token);
|
||||
return -1;
|
||||
if (type == JLEXTOK_WORD) {
|
||||
char* val = strcopy(token);
|
||||
jkval_t* kv = &(parser->kvalarr[parser->kvalsize]);
|
||||
kv->key = strcopy(key);
|
||||
//log_debug("Parser added key %s", kv->key);
|
||||
kv->type = JVALTYPE_STR;
|
||||
kv->str = val;
|
||||
free(key);
|
||||
parser->kvalsize++;
|
||||
pos++;
|
||||
break;
|
||||
}
|
||||
char* val = strcopy(token);
|
||||
|
||||
jkval_t* kv = &(parser->kvalarr[parser->kvalsize]);
|
||||
|
||||
kv->key = strcopy(key);
|
||||
//log_debug("Parser added key %s", kv->key);
|
||||
if (type == JLEXTOK_NUMB) {
|
||||
char* val = strcopy(token);
|
||||
jkval_t* kv = &(parser->kvalarr[parser->kvalsize]);
|
||||
kv->key = strcopy(key);
|
||||
//log_debug("Parser added key %s", kv->key);
|
||||
kv->type = JVALTYPE_NUM;
|
||||
char* eptr = NULL;
|
||||
kv->num = (int64_t)strtol(val, &eptr, 10);;
|
||||
free(val);
|
||||
} else {
|
||||
kv->type = JVALTYPE_STR;
|
||||
kv->str = val;
|
||||
free(key);
|
||||
parser->kvalsize++;
|
||||
pos++;
|
||||
break;
|
||||
}
|
||||
free(key);
|
||||
parser->kvalsize++;
|
||||
pos++;
|
||||
break;
|
||||
if (type == JLEXTOK_RAWSTR) {
|
||||
char* val = strcopy(token);
|
||||
bool isbool = false;
|
||||
bool bval = false;
|
||||
if (strcmp(val, "true") == 0) {
|
||||
isbool = true;
|
||||
bval = true;
|
||||
}
|
||||
if (strcmp(val, "false") == 0) {
|
||||
isbool = true;
|
||||
bval = false;
|
||||
}
|
||||
if (isbool) {
|
||||
jkval_t* kv = &(parser->kvalarr[parser->kvalsize]);
|
||||
kv->key = strcopy(key);
|
||||
log_debug("Parser added bool key %s = %d", kv->key, bval);
|
||||
kv->type = JVALTYPE_BOOL;
|
||||
kv->flag = bval;
|
||||
free(key);
|
||||
parser->kvalsize++;
|
||||
pos++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
log_error("Wrong value token: %s", token);
|
||||
return -1;
|
||||
|
||||
}
|
||||
// POS 4
|
||||
case 4:{
|
||||
@@ -168,6 +198,8 @@ int jparser_bind(jparser_t* parser, int type, char* key, void* ref) {
|
||||
*(char**)(ref) = strcopy(kv->str);
|
||||
} else if (kv->type == JVALTYPE_NUM) {
|
||||
*(int*)(ref) = kv->num;
|
||||
} else if (kv->type == JVALTYPE_BOOL) {
|
||||
*(bool*)(ref) = kv->num;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user