diff options
Diffstat (limited to 'json.h')
| -rw-r--r-- | json.h | 58 |
1 files changed, 29 insertions, 29 deletions
@@ -53,9 +53,9 @@ typedef enum #define json_type_is_valid(type) ((type) >= 0 && (type) < JSON_TYPE_COUNT) -typedef struct json_node json_node; +typedef struct JSON JSON; -struct json_node +struct JSON { json_type type; @@ -77,15 +77,15 @@ struct json_node /* JSON_ARRAY or JSON_OBJECT (children) */ struct { - json_node *head; - json_node *tail; + JSON *head; + JSON *tail; size_t count; } children; } v; - json_node *parent; - json_node *prev; - json_node *next; + JSON *parent; + JSON *prev; + JSON *next; /* * If node is a member of an object, key will be set. Otherwise, key will @@ -94,7 +94,7 @@ struct json_node char *key; size_t key_length; - struct json_node_orig + struct json_orig { /* These only apply if this node is a member of an object. */ struct @@ -117,12 +117,12 @@ struct json_node bool json_validate(const char *str); bool json_validate_server_encoded(const char *str); -json_node *json_decode(const char *str); +JSON *json_decode(const char *str); #define JSONOPT_USE_ORIG 1 #define JSONOPT_ESCAPE_UNICODE 2 #define JSONOPT_NO_TRIM 4 -char *json_encode(json_node * node, int options); +char *json_encode(JSON * node, int options); /* Determines the type of a JSON string without fully decoding it. * Expects the given string to be valid JSON string. @@ -136,13 +136,13 @@ json_type json_text_type(const char *str, size_t nbytes); * a descendant, as this function relies on each node's ->parent field * being trustworthy. */ -void json_delete(json_node * node); +void json_delete(JSON * node); #define json_foreach(child, parent) \ for ((child) = json_head(parent); (child) != NULL; (child) = (child)->next) -static inline json_node * -json_head(json_node * parent) +static inline JSON * +json_head(JSON * parent) { switch (parent->type) { @@ -158,49 +158,49 @@ char *json_decode_string(const char **sp, size_t *length, bool strict); char *json_encode_string(const char *str, size_t length, char quote, bool escape_unicode); /* Add child to parent, putting it at the end. */ -void json_append(json_node * parent, json_node * child); +void json_append(JSON * parent, JSON * child); /* Remove node from its parent. */ -void json_remove(json_node * node); +void json_remove(JSON * node); /* Update the value of a node, preserving position and key information. */ -void json_replace_value(json_node * node, json_node * replacement); +void json_replace_value(JSON * node, JSON * replacement); /* Node factory functions */ -json_node *json_mknode(json_type type); -json_node *json_mkbool(bool v_bool); -json_node *json_mkstring(const char *str, size_t length); -json_node *json_mknumber(const char *number, size_t length); -static inline json_node * +JSON *json_mknode(json_type type); +JSON *json_mkbool(bool v_bool); +JSON *json_mkstring(const char *str, size_t length); +JSON *json_mknumber(const char *number, size_t length); +static inline JSON * json_mkarray(void) { return json_mknode(JSON_ARRAY); } -static inline json_node * +static inline JSON * json_mkobject(void) { return json_mknode(JSON_OBJECT); } -void json_touch_value(json_node * node); +void json_touch_value(JSON * node); /* Node value get/set functions. */ static inline bool -json_get_bool(json_node * node) +json_get_bool(JSON * node) { Assert(node->type == JSON_BOOL); return node->v.v_bool; } static inline void -json_set_bool(json_node * node, bool v_bool) +json_set_bool(JSON * node, bool v_bool) { Assert(node->type == JSON_BOOL); node->v.v_bool = v_bool; json_touch_value(node); } -const char *json_get_string(json_node * node, size_t *length_out); -void json_set_string(json_node * node, const char *str, size_t length); -const char *json_get_number(json_node * node); -void json_set_number(json_node * node, const char *number, size_t length); +const char *json_get_string(JSON * node, size_t *length_out); +void json_set_string(JSON * node, const char *str, size_t length); +const char *json_get_number(JSON * node); +void json_set_number(JSON * node, const char *number, size_t length); #endif |
