sync json.{c,h} - jfconvert - JSON Feed (subset) to sfeed or Atom converter | |
git clone git://git.codemadness.org/jfconvert | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 469bc51805a16876507da21e3145e05bb3c57e72 | |
parent 59db718080ecd81eeaff6ac50298d488044c3001 | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Tue, 4 Apr 2023 18:35:43 +0200 | |
sync json.{c,h} | |
Diffstat: | |
M jf2atom.c | 2 +- | |
M json.c | 15 ++++++++------- | |
M json.h | 2 +- | |
3 files changed, 10 insertions(+), 9 deletions(-) | |
--- | |
diff --git a/jf2atom.c b/jf2atom.c | |
@@ -38,7 +38,7 @@ xmlencode(const char *s, FILE *fp) | |
} | |
void | |
-processnode(struct json_node *nodes, size_t depth, const char *value) | |
+processnode(struct json_node *nodes, size_t depth, const char *value, size_t v… | |
{ | |
const char *outtag, *outtype, *outhref; | |
diff --git a/json.c b/json.c | |
@@ -10,6 +10,7 @@ | |
#include "json.h" | |
+/* ctype-like macros, but always compatible with ASCII / UTF-8 */ | |
#define ISDIGIT(c) (((unsigned)c) - '0' < 10) | |
#define ISXDIGIT(c) ((((unsigned)c) - '0' < 10) || ((unsigned)c | 32) - 'a' < … | |
@@ -93,7 +94,7 @@ capacity(char **value, size_t *sz, size_t cur, size_t inc) | |
#define JSON_INVALID() do { ret = JSON_ERROR_INVALID; goto end; } while … | |
int | |
-parsejson(void (*cb)(struct json_node *, size_t, const char *)) | |
+parsejson(void (*cb)(struct json_node *, size_t, const char *, size_t)) | |
{ | |
struct json_node nodes[JSON_MAX_NODE_DEPTH] = { { 0 } }; | |
size_t depth = 0, p = 0, len, sz = 0; | |
@@ -204,7 +205,7 @@ escchr: | |
goto end; | |
memcpy(nodes[depth].name, str,… | |
} else { | |
- cb(nodes, depth + 1, str); | |
+ cb(nodes, depth + 1, str, len … | |
} | |
break; | |
} else { | |
@@ -233,7 +234,7 @@ escchr: | |
expect = EXPECT_OBJECT_STRING; | |
} | |
- cb(nodes, depth + 1, ""); | |
+ cb(nodes, depth + 1, "", 0); | |
depth++; | |
nodes[depth].index = 0; | |
@@ -268,7 +269,7 @@ escchr: | |
if (GETNEXT() != 'r' || GETNEXT() != 'u' || GETNEXT() … | |
JSON_INVALID(); | |
nodes[depth].type = JSON_TYPE_BOOL; | |
- cb(nodes, depth + 1, "true"); | |
+ cb(nodes, depth + 1, "true", 4); | |
expect = EXPECT_END; | |
break; | |
case 'f': /* false */ | |
@@ -276,14 +277,14 @@ escchr: | |
GETNEXT() != 'e') | |
JSON_INVALID(); | |
nodes[depth].type = JSON_TYPE_BOOL; | |
- cb(nodes, depth + 1, "false"); | |
+ cb(nodes, depth + 1, "false", 5); | |
expect = EXPECT_END; | |
break; | |
case 'n': /* null */ | |
if (GETNEXT() != 'u' || GETNEXT() != 'l' || GETNEXT() … | |
JSON_INVALID(); | |
nodes[depth].type = JSON_TYPE_NULL; | |
- cb(nodes, depth + 1, "null"); | |
+ cb(nodes, depth + 1, "null", 4); | |
expect = EXPECT_END; | |
break; | |
default: /* number */ | |
@@ -298,7 +299,7 @@ escchr: | |
c != '+' && c != '-' && c != '.') || | |
p + 1 >= sizeof(pri)) { | |
pri[p] = '\0'; | |
- cb(nodes, depth + 1, pri); | |
+ cb(nodes, depth + 1, pri, p); | |
goto handlechr; /* do not read next ch… | |
} else { | |
pri[p++] = c; | |
diff --git a/json.h b/json.h | |
@@ -26,5 +26,5 @@ struct json_node { | |
size_t index; /* count/index for array or object type */ | |
}; | |
-int parsejson(void (*cb)(struct json_node *, size_t, const char *)); | |
+int parsejson(void (*cb)(struct json_node *, size_t, const char *, size_t)); | |
#endif |