diff options
| author | Joey Adams | 2010-06-21 23:52:23 +0000 |
|---|---|---|
| committer | Joey Adams | 2010-06-21 23:52:23 +0000 |
| commit | b153d76442ba1ef1237c4cc36f491b3aff7b8510 (patch) | |
| tree | d3d4f0cd8d6d2be370a98b0d13e80dafc6f60bb5 /json.h | |
| parent | f1851e0b1fd7f002b4033d9717ab9a704d402d48 (diff) | |
* Made it so json_path preserves original text.
* Removed the global variable json_escape_unicode and added a parameter for it
to the json_encode and json_encode_string C functions.
Diffstat (limited to 'json.h')
| -rw-r--r-- | json.h | 60 |
1 files changed, 39 insertions, 21 deletions
@@ -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); |
