summaryrefslogtreecommitdiff
path: root/json.h
diff options
context:
space:
mode:
Diffstat (limited to 'json.h')
-rw-r--r--json.h60
1 files changed, 39 insertions, 21 deletions
diff --git a/json.h b/json.h
index 368f672..39b0091 100644
--- a/json.h
+++ b/json.h
@@ -99,25 +99,49 @@ struct json_node {
* For these to be valid, the caller must
* keep the string given to json_decode intact!
*
- * Any pointers that are unknown or not applicable will be NULL.
+ * These pointers are used to preserve original text
+ * after modifications as well as possible.
*
- * Layout:
+ * Layout if node has a key (is a member of an object):
*
- * key_start
- * | key_end
- * | |
- * | | value_start
- * | | | value_end
- * | | | |
- * { "key" : "value" , "otherkey" : "othervalue" }
+ * start
+ * |
+ * | key_start
+ * | | key_end
+ * | | |
+ * | | | value_start
+ * | | | | value_end
+ * | | | | |
+ * | | | | | end
+ * | | | | | |
+ * { "key" : "value" , "otherkey" : "othervalue" }
+ *
+ * Layout if node does not have a key:
+ *
+ * start
+ * |
+ * | value_start
+ * | | value_end
+ * | | |
+ * | | | end
+ * | | | |
+ * [ "value" , "othervalue" ]
*/
struct {
- /* These only apply if this node is a member of an object. */
+ unsigned int used:1, key_changed:1, value_changed:1;
+ /* TODO: Make it so node-altering functions set *_changed bits,
+ propagating up when necessary. */
+
+ const char *start;
+
+ /* These two only apply if this node is a member of an object. */
const char *key_start;
const char *key_end;
const char *value_start;
const char *value_end;
+
+ const char *end;
} orig;
};
@@ -125,8 +149,10 @@ struct json_node {
bool json_validate(const char *str);
bool json_validate_liberal(const char *str);
json_node *json_decode(const char *str);
-json_node *json_decode_liberal(const char *str);
-char *json_encode(json_node *node);
+
+#define JSONOPT_USE_ORIG 1
+#define JSONOPT_ESCAPE_UNICODE 2
+char *json_encode(json_node *node, int options);
/* Determines the type of a JSON string without fully decoding it.
* Expects the given string to be valid JSON string.
@@ -169,15 +195,7 @@ char *json_decode_string(const char **sp, size_t *length, bool strict);
* Returns NULL if input is invalid UTF-8 or if an invalid quote character
* (such as backslash) is given.
*/
-char *json_encode_string(const char *str, size_t length, char quote);
-
-/*
- * Default: false
- *
- * If json_escape_unicode is set, json_encode will escape all Unicode
- * characters, resulting in pure ASCII output.
- */
-extern bool json_escape_unicode;
+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);