summaryrefslogtreecommitdiff
path: root/json.c
diff options
context:
space:
mode:
Diffstat (limited to 'json.c')
-rw-r--r--json.c74
1 files changed, 37 insertions, 37 deletions
diff --git a/json.c b/json.c
index b35c8bf..440f6e0 100644
--- a/json.c
+++ b/json.c
@@ -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);