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

BASE: Now when the string begins by '"', the end of it is not the following space but the next '"'

parent e002c306
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!130Resolve "Remove json-c"
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define __JSON_SPACE " \n\t:=," #define __JSON_SPACE " \n\t:=,"
#define __JSON_BEGIN "{[" #define __JSON_BEGIN "{["
#define __JSON_END "}]" #define __JSON_END "}]"
#define __JSON_SEP '"'
static inline char * static inline char *
strip(char *s) strip(char *s)
...@@ -30,11 +31,27 @@ skip(char *s) ...@@ -30,11 +31,27 @@ skip(char *s)
#define __SKIP_JSON(str) (str = &str[strspn(str, __JSON_SPACE)]) #define __SKIP_JSON(str) (str = &str[strspn(str, __JSON_SPACE)])
#define __NEXT_JSON(str, len, is_paren, dest) \
{ \
is_paren = 0; \
if (str[0] == __JSON_SEP) { \
++str; \
char *end = strchr(str, __JSON_SEP); \
len = (end - str); \
is_paren = 1; \
} else \
len = strcspn(str, __JSON_SPACE __JSON_BEGIN __JSON_END); \
if (level == asked_level && len < LKT_LINE_MAX - 1) \
strncpy(dest, str, len); \
str += len + is_paren; \
}
int int
json_parse(const char *str, int asked_level, json_parse_callback call, void *user) json_parse(const char *str, int asked_level, json_parse_callback call, void *user)
{ {
int level = 0; int level = 0;
int new_obj = 1; int new_obj = 1;
int is_paren = 0;
char key[LKT_LINE_MAX]; char key[LKT_LINE_MAX];
char val[LKT_LINE_MAX]; char val[LKT_LINE_MAX];
...@@ -61,24 +78,14 @@ json_parse(const char *str, int asked_level, json_parse_callback call, void *use ...@@ -61,24 +78,14 @@ json_parse(const char *str, int asked_level, json_parse_callback call, void *use
memset(key, 0, sizeof(key)); memset(key, 0, sizeof(key));
memset(val, 0, sizeof(val)); memset(val, 0, sizeof(val));
len = strcspn(str, __JSON_SPACE __JSON_BEGIN __JSON_END); __NEXT_JSON(str, len, is_paren, key);
if (level == asked_level && len < LKT_LINE_MAX - 1)
strncpy(key, str, len);
str += len;
__SKIP_JSON(str); __SKIP_JSON(str);
__NEXT_JSON(str, len, is_paren, val);
len = strcspn(str, __JSON_SPACE __JSON_BEGIN __JSON_END);
if (level == asked_level && len < LKT_LINE_MAX - 1)
strncpy(val, str, len);
str += len;
if (asked_level == level) if (asked_level == level)
call(key, val, new_obj, user); call(key, val, new_obj, user);
if (new_obj) new_obj = 0;
new_obj = 0;
} }
if (level <= 0) { 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