Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 3a9354e0 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

BASE: Completion call for the json parser

parent 64aecb75
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!130Resolve "Remove json-c"
......@@ -12,15 +12,17 @@
// *INDENT-OFF*
typedef void(*json_parse_callback)(
const char *key, /* Json key, a string */
const char *value, /* Json value, a string */
int new_obj, /* 1 when encountered a new object */
void *user /* The user pointer from the parse function */
const char *key, /* Json key, a string */
const char *value, /* Json value, a string */
int completed, /* 1 when all values in the object has been parsed */
void *user /* The user pointer from the parse function */
);
// *INDENT-ON*
/* Parse only one level of json, simple but only what we need for lektor. The
* callback is used when a couple key/value is found for the correct level. */
* callback is used when a couple key/value is found for the correct level.
* When the json object has been completed, call the callback with the
* 'completed' argument at 1, 'key' and 'value' will be NULL. */
int json_parse(const char *str, int level, json_parse_callback, void *user);
#endif /* __LKT_JSON_H__ */
......@@ -94,7 +94,6 @@ int
json_parse(const char *str, int asked_level, json_parse_callback call, void *user)
{
int level = 0;
int new_obj = 1;
int is_paren = 0;
char key[LKT_LINE_MAX];
char val[LKT_LINE_MAX];
......@@ -105,14 +104,15 @@ json_parse(const char *str, int asked_level, json_parse_callback call, void *use
/* Begin of a block */
if ((len = strspn(str, __JSON_BEGIN))) {
new_obj = 1;
level += len;
str += len;
}
/* End of a block */
else if ((len = strspn(str, __JSON_END))) {
new_obj = 1;
if (level == asked_level) {
call(NULL, NULL, 1, user);
}
str += len;
level -= len;
}
......@@ -127,9 +127,7 @@ json_parse(const char *str, int asked_level, json_parse_callback call, void *use
__NEXT_JSON(str, len, is_paren, val);
if (asked_level == level)
call(key, val, new_obj, user);
new_obj = 0;
call(key, val, 0, user);
}
if (level <= 0) {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter