diff options
| author | Joey Adams | 2010-08-05 03:53:30 +0000 |
|---|---|---|
| committer | Joey Adams | 2010-08-05 03:53:30 +0000 |
| commit | 1dab8166427da17d43c6ebaa6287447d3dd174b5 (patch) | |
| tree | 54c1e57b485f3136c2a607cab326a151a9978e8e | |
| parent | 32df49240df9b682cbe1b9d307e16eda08572109 (diff) | |
Renamed json_node to JSON in the C code.
| -rw-r--r-- | json.c | 74 | ||||
| -rw-r--r-- | json.h | 58 | ||||
| -rw-r--r-- | json_io.c | 4 | ||||
| -rw-r--r-- | json_op.c | 8 | ||||
| -rw-r--r-- | jsonpath.c | 18 | ||||
| -rw-r--r-- | jsonpath.h | 6 |
6 files changed, 84 insertions, 84 deletions
@@ -31,7 +31,7 @@ skip_whitespace(const char **sp) } static char -end_parenthesis(json_node * node) +end_parenthesis(JSON * node) { if (!node) return 0; @@ -91,31 +91,31 @@ write_hex16(char *out, unsigned int val) } -/*********** json_node creation, manipulation, and deletion **********/ +/*********** JSON creation, manipulation, and deletion **********/ -json_node * +JSON * json_mknode(json_type type) { - json_node *node = palloc(sizeof(*node)); + JSON *node = palloc(sizeof(*node)); memset(node, 0, sizeof(*node)); node->type = type; return node; } -json_node * +JSON * json_mkbool(bool v_bool) { - json_node *node = json_mknode(JSON_BOOL); + JSON *node = json_mknode(JSON_BOOL); node->v.v_bool = v_bool; return node; } -json_node * +JSON * json_mkstring(const char *str, size_t length) { - json_node *node = json_mknode(JSON_STRING); + JSON *node = json_mknode(JSON_STRING); if (str) { @@ -125,10 +125,10 @@ json_mkstring(const char *str, size_t length) return node; } -json_node * +JSON * json_mknumber(const char *number, size_t length) { - json_node *node = json_mknode(JSON_NUMBER); + JSON *node = json_mknode(JSON_NUMBER); if (number) node->v.number = pnstrdup(number, length); @@ -142,7 +142,7 @@ json_mknumber(const char *number, size_t length) * will encode the new value rather than using original text. */ void -json_touch_value(json_node * node) +json_touch_value(JSON * node) { while (node && node->orig.value.start) { @@ -152,7 +152,7 @@ json_touch_value(json_node * node) } static void -json_append_notouch(json_node * parent, json_node * child) +json_append_notouch(JSON * parent, JSON * child) { Assert(parent->type == JSON_ARRAY || parent->type == JSON_OBJECT); Assert(child->parent == NULL); @@ -174,16 +174,16 @@ json_append_notouch(json_node * parent, json_node * child) } void -json_append(json_node * parent, json_node * child) +json_append(JSON * parent, JSON * child) { json_append_notouch(parent, child); json_touch_value(parent); } void -json_remove(json_node * node) +json_remove(JSON * node) { - json_node *parent = node->parent; + JSON *parent = node->parent; if (!parent) return; @@ -208,7 +208,7 @@ json_remove(json_node * node) } void -json_replace_value(json_node * node, json_node * replacement) +json_replace_value(JSON * node, JSON * replacement) { node->type = replacement->type; node->v = replacement->v; @@ -219,7 +219,7 @@ json_replace_value(json_node * node, json_node * replacement) } const char * -json_get_string(json_node * node, size_t *length_out) +json_get_string(JSON * node, size_t *length_out) { Assert(node->type == JSON_STRING); if (length_out) @@ -228,7 +228,7 @@ json_get_string(json_node * node, size_t *length_out) } void -json_set_string(json_node * node, const char *str, size_t length) +json_set_string(JSON * node, const char *str, size_t length) { Assert(node->type == JSON_STRING); if (node->v.string.str) @@ -247,14 +247,14 @@ json_set_string(json_node * node, const char *str, size_t length) } const char * -json_get_number(json_node * node) +json_get_number(JSON * node) { Assert(node->type == JSON_NUMBER); return node->v.number; } void -json_set_number(json_node * node, const char *number, size_t length) +json_set_number(JSON * node, const char *number, size_t length) { Assert(node->type == JSON_NUMBER); if (node->v.number) @@ -268,7 +268,7 @@ json_set_number(json_node * node, const char *number, size_t length) /* Non-recursively free a node */ static void -free_node(json_node * node) +free_node(JSON * node) { if (node->type == JSON_STRING) { @@ -288,9 +288,9 @@ free_node(json_node * node) } void -json_delete(json_node * node) +json_delete(JSON * node) { - json_node *parent, + JSON *parent, *next; if (!node) @@ -328,8 +328,8 @@ ascend: /*********************** Parsing and validation **********************/ -static json_node *decode_leaf(const char **sp); -static json_node *decode_number(const char **sp); +static JSON *decode_leaf(const char **sp); +static JSON *decode_number(const char **sp); char *json_decode_string(const char **sp, size_t *length, bool strict); /* json_decode_string has a different signature than its friends @@ -347,7 +347,7 @@ char *json_decode_string(const char **sp, size_t *length, bool strict); bool json_validate(const char *str) { - json_node *node = json_decode(str); + JSON *node = json_decode(str); if (!node) return false; @@ -381,16 +381,16 @@ json_validate_server_encoded(const char *str) * Convert a JSON-encoded string to a JSON node. * @str must be valid UTF-8. */ -json_node * +JSON * json_decode(const char *str) { - json_node *root = NULL, + JSON *root = NULL, *parent = NULL, *node = NULL; const char *s = str; char *key; size_t key_length; - struct json_node_orig orig; + struct json_orig orig; bool expect_endp; if (!str) @@ -568,7 +568,7 @@ failed: /* Handle failure */ * * Returns NULL if next character is '[', '{', or invalid. */ -static json_node * +static JSON * decode_leaf(const char **sp) { char c = **sp; @@ -580,7 +580,7 @@ decode_leaf(const char **sp) if (str) { - json_node *node = json_mknode(JSON_STRING); + JSON *node = json_mknode(JSON_STRING); node->v.string.str = str; node->v.string.length = length; @@ -671,7 +671,7 @@ validate_number(const char **sp) return true; } -static json_node * +static JSON * decode_number(const char **sp) { const char *start, @@ -987,10 +987,10 @@ typedef struct bool trim; } json_encode_ctx; -static bool json_encode_recurse(json_node * node, json_encode_ctx * ctx); +static bool json_encode_recurse(JSON * node, json_encode_ctx * ctx); char * -json_encode(json_node * node, int options) +json_encode(JSON * node, int options) { json_encode_ctx ctx; @@ -1009,7 +1009,7 @@ json_encode(json_node * node, int options) } static bool -json_encode_recurse(json_node * node, json_encode_ctx * ctx) +json_encode_recurse(JSON * node, json_encode_ctx * ctx) { #define has_orig(field) \ (use_orig && node->orig.field.start) @@ -1033,7 +1033,7 @@ json_encode_recurse(json_node * node, json_encode_ctx * ctx) else { const char *txt = NULL; - json_node *child; + JSON *child; switch (node->type) { @@ -1077,7 +1077,7 @@ json_encode_recurse(json_node * node, json_encode_ctx * ctx) * @node) so we can use our macros on the child node * instead. Hurray for lexical scoping! */ - json_node *node = child; + JSON *node = child; if (has_orig(key_left_space)) push_orig(key_left_space); @@ -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 @@ -121,7 +121,7 @@ static const char * from_json_cstring(const char *input) { size_t len; - json_node *json = json_decode(input); + JSON *json = json_decode(input); const char *cstring_out = NULL; if (json == NULL) @@ -264,7 +264,7 @@ datum_to_json(Datum datum, TypeInfo *typeInfo, json_type target_type) { char *cstring; char *cstring_utf8; - json_node *node; + JSON *node; char *encoded_utf8; switch (target_type) @@ -67,7 +67,7 @@ Datum json_condense(PG_FUNCTION_ARGS) { char *string; - json_node *json; + JSON *json; char *condensed; string = text_to_utf8_cstring(PG_GETARG_JSON_P(0)); @@ -86,7 +86,7 @@ json_path_base(FunctionCallInfo fcinfo) char *json_string = text_to_utf8_cstring(PG_GETARG_JSON_P(0)); char *path_string = text_to_utf8_cstring(PG_GETARG_TEXT_PP(1)); JSONPath *jpath = jp_parse(path_string); - json_node *json = json_decode(json_string); + JSON *json = json_decode(json_string); List *result_list; if (!jpath) @@ -148,8 +148,8 @@ json_set(PG_FUNCTION_ARGS) char *path_string = text_to_utf8_cstring(PG_GETARG_TEXT_PP(1)); char *rvalue_string = text_to_utf8_cstring(PG_GETARG_JSON_P(2)); JSONPath *jpath = jp_parse(path_string); - json_node *json = json_decode(json_string); - json_node *rvalue = json_decode(rvalue_string); + JSON *json = json_decode(json_string); + JSON *rvalue = json_decode(rvalue_string); char *result; jsontype *result_text; @@ -140,7 +140,7 @@ mkRef(JPRefType type) } static JPRef * -mkRefNode(json_node * node) +mkRefNode(JSON * node) { JPRef *ref = mkRef(JP_REF_NODE); @@ -390,17 +390,17 @@ failed: } /* - * Currently, a lot of JPRef nodes are allocated just to pass json_node pointers + * Currently, a lot of JPRef nodes are allocated just to pass JSON pointers * to match_recurse. If this becomes a memory/performance issue in the future, - * JPRef could merged with json_node by adding JPRef's specialty types to the - * json_type enum and json_node union. JPRef is currently not merged with - * json_node in an attempt to keep the codebase tidy and easier to extend. + * JPRef could merged with JSON by adding JPRef's specialty types to the + * json_type enum and JSON union. JPRef is currently not merged with + * JSON in an attempt to keep the codebase tidy and easier to extend. */ static void match_recurse(void on_match(void *ctx, JPRef * ref), void *ctx, ListCell *path, JPRef * ref) { jp_element *elem; - json_node *json, + JSON *json, *child; if (path == NULL) @@ -514,7 +514,7 @@ jp_match_callback(List **results, JPRef * ref) } List * -jp_match(JSONPath * jp, json_node * json) +jp_match(JSONPath * jp, JSON * json) { ListCell *lc = jp_head(jp); List *results = NIL; @@ -525,7 +525,7 @@ jp_match(JSONPath * jp, json_node * json) } static void -jp_set_callback(json_node * value, JPRef * ref) +jp_set_callback(JSON * value, JPRef * ref) { switch (ref->type) { @@ -539,7 +539,7 @@ jp_set_callback(json_node * value, JPRef * ref) } void -jp_set(JSONPath * jp, json_node * json, json_node * value) +jp_set(JSONPath * jp, JSON * json, JSON * value) { ListCell *lc = jp_head(jp); @@ -55,7 +55,7 @@ typedef struct union { - json_node *node; + JSON *node; struct { @@ -70,8 +70,8 @@ typedef List /* jp_element* */ JSONPath; JSONPath *jp_parse(const char *pattern); char *jp_show(JSONPath * jp); -List /* JPRef* */ *jp_match(JSONPath * jp, json_node * json); -void jp_set(JSONPath * jp, json_node * json, json_node * value); +List /* JPRef* */ *jp_match(JSONPath * jp, JSON * json); +void jp_set(JSONPath * jp, JSON * json, JSON * value); /* Returns the JSON encoding of the given reference. */ char *jpref_encode(JPRef * ref); |
