| JSONChildren.h | | JSONChildren.h | |
| | | | |
| skipping to change at line 15 | | skipping to change at line 15 | |
| #include "JSONDebug.h" //for JSON_ASSERT macro | | #include "JSONDebug.h" //for JSON_ASSERT macro | |
| | | | |
| #define json_foreach(children, iterator)\ | | #define json_foreach(children, iterator)\ | |
| JSONNode ** iterator = children.begin();\ | | JSONNode ** iterator = children.begin();\ | |
| for(JSONNode ** iterator##_end = children.end(); iterator != iterator##
_end; ++iterator) | | for(JSONNode ** iterator##_end = children.end(); iterator != iterator##
_end; ++iterator) | |
| | | | |
| /* | | /* | |
| This class is essentially a vector that has been heavily optimized for the
specific purpose | | This class is essentially a vector that has been heavily optimized for the
specific purpose | |
| of holding JSONNode children. It acts the same way as a vector, it has a
automatically | | of holding JSONNode children. It acts the same way as a vector, it has a
automatically | |
| expanding array. On destruction, this container automatically destroys ev
erything contained | | expanding array. On destruction, this container automatically destroys ev
erything contained | |
|
| in it as well, so that you libJSON doesn't have to do that. | | in it as well, so that you libjson doesn't have to do that. | |
| | | | |
| T is JSONNode*, I can't define it that way directly because JSONNode uses
this container, and because | | T is JSONNode*, I can't define it that way directly because JSONNode uses
this container, and because | |
| the container deletes the children automatically, forward declaration can'
t be used | | the container deletes the children automatically, forward declaration can'
t be used | |
| */ | | */ | |
| | | | |
| class JSONNode; //forward declaration | | class JSONNode; //forward declaration | |
| | | | |
| class jsonChildren { | | class jsonChildren { | |
| public: | | public: | |
| //starts completely empty and the array is not allocated | | //starts completely empty and the array is not allocated | |
| | | | |
End of changes. 1 change blocks. |
| 1 lines changed or deleted | | 1 lines changed or added | |
|
| JSONDefs.h | | JSONDefs.h | |
| | | | |
| skipping to change at line 20 | | skipping to change at line 20 | |
| #include "../JSONOptions.h" | | #include "../JSONOptions.h" | |
| | | | |
| #define JSON_NULL '\0' | | #define JSON_NULL '\0' | |
| #define JSON_STRING '\1' | | #define JSON_STRING '\1' | |
| #define JSON_NUMBER '\2' | | #define JSON_NUMBER '\2' | |
| #define JSON_BOOL '\3' | | #define JSON_BOOL '\3' | |
| #define JSON_ARRAY '\4' | | #define JSON_ARRAY '\4' | |
| #define JSON_NODE '\5' | | #define JSON_NODE '\5' | |
| | | | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
|
| #include <string> | | #ifdef JSON_STRING_HEADER | |
| | | #include JSON_STRING_HEADER | |
| | | #else | |
| | | #include <string> | |
| | | #endif | |
| #endif | | #endif | |
| | | | |
| #ifdef JSON_UNICODE | | #ifdef JSON_UNICODE | |
| #ifdef JSON_ISO_STRICT | | #ifdef JSON_ISO_STRICT | |
| #error, You can not use unicode under ISO Strict C++ | | #error, You can not use unicode under ISO Strict C++ | |
| #endif | | #endif | |
| #define json_char wchar_t | | #define json_char wchar_t | |
|
| | | #define json_uchar wchar_t | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
| #include <cwchar> //need wide characters | | #include <cwchar> //need wide characters | |
|
| typedef std::wstring json_string; | | #ifndef JSON_STRING_HEADER | |
| | | typedef std::wstring json_string; | |
| | | #endif | |
| #else | | #else | |
| #include <wchar.h> //need wide characters | | #include <wchar.h> //need wide characters | |
| #endif | | #endif | |
| #define JSON_TEXT(s) L ## s | | #define JSON_TEXT(s) L ## s | |
| #define json_strlen wcslen | | #define json_strlen wcslen | |
| #define json_strcmp wcscmp | | #define json_strcmp wcscmp | |
| #else | | #else | |
| #define json_char char | | #define json_char char | |
|
| | | #define json_uchar unsigned char | |
| #ifdef __cplusplus | | #ifdef __cplusplus | |
|
| typedef std::string json_string; | | #ifndef JSON_STRING_HEADER | |
| | | typedef std::string json_string; | |
| | | #endif | |
| #endif | | #endif | |
| #define JSON_TEXT(s) s | | #define JSON_TEXT(s) s | |
| #define json_strlen strlen | | #define json_strlen strlen | |
| #define json_strcmp strcmp | | #define json_strcmp strcmp | |
| #endif | | #endif | |
| | | | |
| #ifdef JSON_LESS_MEMORY | | #ifdef JSON_LESS_MEMORY | |
| #define BITS(x) :x //tells the compiler how many bits to use for a fie
ld | | #define BITS(x) :x //tells the compiler how many bits to use for a fie
ld | |
|
| | | #define START_MEM_SCOPE { | |
| | | #define END_MEM_SCOPE } | |
| typedef float json_number; | | typedef float json_number; | |
| #else | | #else | |
| #define BITS(x) | | #define BITS(x) | |
|
| | | #define START_MEM_SCOPE | |
| | | #define END_MEM_SCOPE | |
| typedef double json_number; | | typedef double json_number; | |
| #endif | | #endif | |
| | | | |
| #if defined JSON_DEBUG || defined JSON_SAFE | | #if defined JSON_DEBUG || defined JSON_SAFE | |
| #ifdef JSON_LIBRARY | | #ifdef JSON_LIBRARY | |
| typedef void (*json_error_callback_t)(const json_char *); | | typedef void (*json_error_callback_t)(const json_char *); | |
| #else | | #else | |
| typedef void (*json_error_callback_t)(const json_string &); | | typedef void (*json_error_callback_t)(const json_string &); | |
| #endif | | #endif | |
| #endif | | #endif | |
| | | | |
End of changes. 7 change blocks. |
| 3 lines changed or deleted | | 17 lines changed or added | |
|
| JSONNode.h | | JSONNode.h | |
| | | | |
| skipping to change at line 130 | | skipping to change at line 130 | |
| | | | |
| json_string as_string(void) const; | | json_string as_string(void) const; | |
| long as_int(void) const; | | long as_int(void) const; | |
| json_number as_float(void) const; | | json_number as_float(void) const; | |
| bool as_bool(void) const; | | bool as_bool(void) const; | |
| JSONNode as_node(void) const; | | JSONNode as_node(void) const; | |
| JSONNode as_array(void) const; | | JSONNode as_array(void) const; | |
| | | | |
| #ifdef JSON_BINARY | | #ifdef JSON_BINARY | |
| std::string as_binary(void) const; | | std::string as_binary(void) const; | |
|
| void set_binary(const unsigned char * bin, json_index_t bytes); | | void set_binary(const unsigned char * bin, size_t bytes); | |
| #endif | | #endif | |
| | | | |
| JSONNode & at(json_index_t pos); | | JSONNode & at(json_index_t pos); | |
| const JSONNode & at(json_index_t pos) const; | | const JSONNode & at(json_index_t pos) const; | |
| JSONNode & operator[](json_index_t pos); | | JSONNode & operator[](json_index_t pos); | |
| const JSONNode & operator[](json_index_t pos) const; | | const JSONNode & operator[](json_index_t pos) const; | |
| | | | |
| JSONNode & at(const json_string & name_t); | | JSONNode & at(const json_string & name_t); | |
| const JSONNode & at(const json_string & name_t) const; | | const JSONNode & at(const json_string & name_t) const; | |
| #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS | | #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS | |
| | | | |
| skipping to change at line 152 | | skipping to change at line 152 | |
| const JSONNode & at_nocase(const json_string & name_t) const; | | const JSONNode & at_nocase(const json_string & name_t) const; | |
| #endif | | #endif | |
| JSONNode & operator[](const json_string & name_t); | | JSONNode & operator[](const json_string & name_t); | |
| const JSONNode & operator[](const json_string & name_t) const; | | const JSONNode & operator[](const json_string & name_t) const; | |
| | | | |
| #ifdef JSON_LIBRARY | | #ifdef JSON_LIBRARY | |
| void push_back(JSONNode * node); | | void push_back(JSONNode * node); | |
| #else | | #else | |
| void push_back(const JSONNode & node); | | void push_back(const JSONNode & node); | |
| #endif | | #endif | |
|
| void reserve(json_index_t size); | | void reserve(json_index_t siz); | |
| JSONNode JSON_PTR_LIB pop_back(json_index_t pos); | | JSONNode JSON_PTR_LIB pop_back(json_index_t pos); | |
| JSONNode JSON_PTR_LIB pop_back(const json_string & name_t); | | JSONNode JSON_PTR_LIB pop_back(const json_string & name_t); | |
| #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS | | #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS | |
| JSONNode JSON_PTR_LIB pop_back_nocase(const json_string & name_t)
; | | JSONNode JSON_PTR_LIB pop_back_nocase(const json_string & name_t)
; | |
| #endif | | #endif | |
| | | | |
| DECLARE_FOR_ALL_TYPES(JSONNode & operator =) | | DECLARE_FOR_ALL_TYPES(JSONNode & operator =) | |
| JSONNode & operator = (const JSONNode &); | | JSONNode & operator = (const JSONNode &); | |
| | | | |
| DECLARE_FOR_ALL_TYPES_CONST(bool operator ==) | | DECLARE_FOR_ALL_TYPES_CONST(bool operator ==) | |
| | | | |
| skipping to change at line 573 | | skipping to change at line 573 | |
| JSON_CHECK_INTERNAL(); | | JSON_CHECK_INTERNAL(); | |
| return internal -> as_float(); | | return internal -> as_float(); | |
| } | | } | |
| | | | |
| inline bool JSONNode::as_bool(void) const { | | inline bool JSONNode::as_bool(void) const { | |
| JSON_CHECK_INTERNAL(); | | JSON_CHECK_INTERNAL(); | |
| return internal -> as_bool(); | | return internal -> as_bool(); | |
| } | | } | |
| | | | |
| #ifdef JSON_BINARY | | #ifdef JSON_BINARY | |
|
| inline void JSONNode::set_binary(const unsigned char * bin, json_index_
t bytes){ | | inline void JSONNode::set_binary(const unsigned char * bin, size_t byte
s){ | |
| JSON_CHECK_INTERNAL(); | | JSON_CHECK_INTERNAL(); | |
| *this = JSONBase64::json_encode64(bin, bytes); | | *this = JSONBase64::json_encode64(bin, bytes); | |
| } | | } | |
| | | | |
| inline std::string JSONNode::as_binary(void) const { | | inline std::string JSONNode::as_binary(void) const { | |
|
| JSON_ASSERT_SAFE(type() == JSON_STRING, JSON_TEXT("using as_binar
y for a non-string type"), return EMPTY_STRING2;); | | JSON_ASSERT_SAFE(type() == JSON_STRING, JSON_TEXT("using as_binar
y for a non-string type"), return EMPTY_STD_STRING;); | |
| JSON_CHECK_INTERNAL(); | | JSON_CHECK_INTERNAL(); | |
| return JSONBase64::json_decode64(as_string()); | | return JSONBase64::json_decode64(as_string()); | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| inline JSONNode & JSONNode::operator[](const json_string & name_t){ | | inline JSONNode & JSONNode::operator[](const json_string & name_t){ | |
| JSON_CHECK_INTERNAL(); | | JSON_CHECK_INTERNAL(); | |
| makeUniqueInternal(); | | makeUniqueInternal(); | |
| return *(*(internal -> at(name_t))); | | return *(*(internal -> at(name_t))); | |
| } | | } | |
| | | | |
| skipping to change at line 606 | | skipping to change at line 606 | |
| #ifdef JSON_LIBRARY | | #ifdef JSON_LIBRARY | |
| inline void JSONNode::push_back(JSONNode * child){ | | inline void JSONNode::push_back(JSONNode * child){ | |
| #else | | #else | |
| inline void JSONNode::push_back(const JSONNode & child){ | | inline void JSONNode::push_back(const JSONNode & child){ | |
| #endif | | #endif | |
| JSON_CHECK_INTERNAL(); | | JSON_CHECK_INTERNAL(); | |
| makeUniqueInternal(); | | makeUniqueInternal(); | |
| internal -> push_back(child); | | internal -> push_back(child); | |
| } | | } | |
| | | | |
|
| inline void JSONNode::reserve(json_index_t size){ | | inline void JSONNode::reserve(json_index_t siz){ | |
| makeUniqueInternal(); | | makeUniqueInternal(); | |
|
| internal -> reserve(size); | | internal -> reserve(siz); | |
| } | | } | |
| | | | |
| inline JSONNode & JSONNode::operator = (const JSONNode & orig){ | | inline JSONNode & JSONNode::operator = (const JSONNode & orig){ | |
| JSON_CHECK_INTERNAL(); | | JSON_CHECK_INTERNAL(); | |
| #ifdef JSON_REF_COUNT | | #ifdef JSON_REF_COUNT | |
| if (internal == orig.internal) return *this; //don't want it acc
identally deleting itself | | if (internal == orig.internal) return *this; //don't want it acc
identally deleting itself | |
| #endif | | #endif | |
| decRef(); //dereference my current one | | decRef(); //dereference my current one | |
| internal = orig.internal -> incRef(); //increase reference of original | | internal = orig.internal -> incRef(); //increase reference of original | |
| return *this; | | return *this; | |
| | | | |
| skipping to change at line 812 | | skipping to change at line 812 | |
| #endif | | #endif | |
| | | | |
| inline JSONNode::json_iterator JSONNode::insert(json_iterator pos, cons
t json_iterator & _start, const json_iterator & _end){ | | inline JSONNode::json_iterator JSONNode::insert(json_iterator pos, cons
t json_iterator & _start, const json_iterator & _end){ | |
| return insertFFF(pos, json_iterator_ptr(_start), json_iterator_pt
r(_end)); | | return insertFFF(pos, json_iterator_ptr(_start), json_iterator_pt
r(_end)); | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| #ifdef JSON_WRITER | | #ifdef JSON_WRITER | |
| inline json_string JSONNode::write(void){ | | inline json_string JSONNode::write(void){ | |
| JSON_CHECK_INTERNAL(); | | JSON_CHECK_INTERNAL(); | |
|
| JSON_ASSERT_SAFE(type() == JSON_NODE || type() == JSON_ARRAY, JSO
N_TEXT("Writing a non-writable node"), return JSON_TEXT("");); | | JSON_ASSERT_SAFE(type() == JSON_NODE || type() == JSON_ARRAY, JSO
N_TEXT("Writing a non-writable node"), return EMPTY_JSON_STRING;); | |
| return internal -> Write(0xFFFFFFFF, true); | | return internal -> Write(0xFFFFFFFF, true); | |
| } | | } | |
| | | | |
| inline json_string JSONNode::write_formatted(void){ | | inline json_string JSONNode::write_formatted(void){ | |
| JSON_CHECK_INTERNAL(); | | JSON_CHECK_INTERNAL(); | |
|
| JSON_ASSERT_SAFE(type() == JSON_NODE || type() == JSON_ARRAY, JSO
N_TEXT("Writing a non-writable node"), return JSON_TEXT("");); | | JSON_ASSERT_SAFE(type() == JSON_NODE || type() == JSON_ARRAY, JSO
N_TEXT("Writing a non-writable node"), return EMPTY_JSON_STRING;); | |
| return internal -> Write(0, true); | | return internal -> Write(0, true); | |
| } | | } | |
| | | | |
| #endif | | #endif | |
| | | | |
| #ifndef JSON_PREPARSE | | #ifndef JSON_PREPARSE | |
| inline void JSONNode::preparse(void){ | | inline void JSONNode::preparse(void){ | |
| JSON_CHECK_INTERNAL(); | | JSON_CHECK_INTERNAL(); | |
| internal -> preparse(); | | internal -> preparse(); | |
| } | | } | |
| | | | |
End of changes. 8 change blocks. |
| 8 lines changed or deleted | | 8 lines changed or added | |
|
| JSONOptions.h | | JSONOptions.h | |
| | | | |
| skipping to change at line 37 | | skipping to change at line 37 | |
| * from the errors that it encounters. This option is recommended for tho
se who | | * from the errors that it encounters. This option is recommended for tho
se who | |
| * feel it's possible for their program to encounter invalid json. | | * feel it's possible for their program to encounter invalid json. | |
| */ | | */ | |
| #define JSON_SAFE | | #define JSON_SAFE | |
| | | | |
| /* | | /* | |
| * JSON_STDERROR routes error messages to cerr instead of a callback, this | | * JSON_STDERROR routes error messages to cerr instead of a callback, this | |
| * option hides the callback registering function. This will usually disp
lay | | * option hides the callback registering function. This will usually disp
lay | |
| * messages in the console | | * messages in the console | |
| */ | | */ | |
|
| #define JSON_STDERROR | | //#define JSON_STDERROR | |
| | | | |
| /* | | /* | |
| * JSON_PREPARSE causes all parsing to be done immediately. By default, l
ibjson | | * JSON_PREPARSE causes all parsing to be done immediately. By default, l
ibjson | |
| * parses nodes on the fly as they are needed, this makes parsing much fas
ter if | | * parses nodes on the fly as they are needed, this makes parsing much fas
ter if | |
| * your program gets a lot of information that it doesn't need. An exampl
e of | | * your program gets a lot of information that it doesn't need. An exampl
e of | |
| * this would be a client application communicating with a server if the s
erver | | * this would be a client application communicating with a server if the s
erver | |
| * returns things like last modified date and other things that you don't
use. | | * returns things like last modified date and other things that you don't
use. | |
| */ | | */ | |
| //#define JSON_PREPARSE | | //#define JSON_PREPARSE | |
| | | | |
| | | | |
| skipping to change at line 78 | | skipping to change at line 78 | |
| */ | | */ | |
| #define JSON_REF_COUNT | | #define JSON_REF_COUNT | |
| | | | |
| /* | | /* | |
| * JSON_BINARY is used to support binary, which is base64 encoded and deco
ded by libjson, | | * JSON_BINARY is used to support binary, which is base64 encoded and deco
ded by libjson, | |
| * if this option is not turned on, no base64 support is included | | * if this option is not turned on, no base64 support is included | |
| */ | | */ | |
| //#define JSON_BINARY | | //#define JSON_BINARY | |
| | | | |
| /* | | /* | |
|
| | | * JSON_ITERATORS turns on all of libjson's iterating functionality. This | |
| | | would usually | |
| | | * only be turned off while compiling for use with C | |
| | | */ | |
| | | //#define JSON_ITERATORS | |
| | | | |
| | | /* | |
| * JSON_MEMORY_CALLBACKS exposes functions to register callbacks for alloc
ating, resizing, | | * JSON_MEMORY_CALLBACKS exposes functions to register callbacks for alloc
ating, resizing, | |
| * and freeing memory. Because libjson is designed for costomizability, i
t is feasible | | * and freeing memory. Because libjson is designed for costomizability, i
t is feasible | |
| * that some users would like to further add speed by having the library u
tilize a memory | | * that some users would like to further add speed by having the library u
tilize a memory | |
| * pool. With this option turned on, the default behavior is still done i
nternally unless | | * pool. With this option turned on, the default behavior is still done i
nternally unless | |
| * a callback is registered. So you can have this option on and mot use i
t. | | * a callback is registered. So you can have this option on and mot use i
t. | |
| */ | | */ | |
| //#define JSON_MEMORY_CALLBACKS | | //#define JSON_MEMORY_CALLBACKS | |
| | | | |
| /* | | /* | |
| * JSON_MEMORY_MANAGE is used to create functionality to automatically tra
ck and clean | | * JSON_MEMORY_MANAGE is used to create functionality to automatically tra
ck and clean | |
| | | | |
| skipping to change at line 117 | | skipping to change at line 123 | |
| */ | | */ | |
| //#define JSON_MUTEX_MANAGE | | //#define JSON_MUTEX_MANAGE | |
| | | | |
| /* | | /* | |
| * JSON_ISO_STRICT turns off all code that uses non-standard C++. This re
moves all | | * JSON_ISO_STRICT turns off all code that uses non-standard C++. This re
moves all | |
| * references to long long and long double as well as a few others | | * references to long long and long double as well as a few others | |
| */ | | */ | |
| //#define JSON_ISO_STRICT | | //#define JSON_ISO_STRICT | |
| | | | |
| /* | | /* | |
|
| * JSON_ITERATORS turns on all of libjson's iterating functionality. This | | * JSON_NO_C_CONSTS removes consts from the C interface. It still acts th | |
| would usually | | e same way, but | |
| * only be turned off while compiling for use with C | | * this may be useful for using the header with languages or variants that | |
| | | don't have const | |
| */ | | */ | |
|
| //#define JSON_ITERATORS | | //#define JSON_NO_C_CONSTS | |
| | | | |
| /* | | /* | |
| * JSON_WRITER turns on libjson's writing capabilties. Without this libjs
on can only | | * JSON_WRITER turns on libjson's writing capabilties. Without this libjs
on can only | |
| * read and parse json, this allows it to write back out | | * read and parse json, this allows it to write back out | |
| */ | | */ | |
| #define JSON_WRITER | | #define JSON_WRITER | |
| | | | |
| /* | | /* | |
| * JSON_NEWLINE affects how libjson writes. If this option is turned on,
libjson | | * JSON_NEWLINE affects how libjson writes. If this option is turned on,
libjson | |
| * will use whatever it's defined as for the newline signifier, otherwise,
it will use | | * will use whatever it's defined as for the newline signifier, otherwise,
it will use | |
| * standard unix \n. | | * standard unix \n. | |
| */ | | */ | |
| //#define JSON_NEWLINE "\r\n" //\r\n is standard for most windows and dos
programs | | //#define JSON_NEWLINE "\r\n" //\r\n is standard for most windows and dos
programs | |
| | | | |
| /* | | /* | |
|
| * JSON_COMMENTS tells libjson to store and write comments. libjson alway | | | |
| s supports | | | |
| * parsing json that has comments in it as it simply ignores them, but wit | | | |
| h this option | | | |
| * it keeps the comments and allows you to insert further comments | | | |
| */ | | | |
| #define JSON_COMMENTS | | | |
| | | | |
| /* | | | |
| * JSON_INDENT affects how libjson writes. If this option is turned on, l
ibjson | | * JSON_INDENT affects how libjson writes. If this option is turned on, l
ibjson | |
| * will use \t to indent formatted json, otherwise it will use the number
of characters | | * will use \t to indent formatted json, otherwise it will use the number
of characters | |
| * that you specify. If this is not turned on, then it will use the tab (
\t) character | | * that you specify. If this is not turned on, then it will use the tab (
\t) character | |
| */ | | */ | |
| //#define JSON_INDENT " " | | //#define JSON_INDENT " " | |
| | | | |
| /* | | /* | |
|
| | | * JSON_ESCAPE_WRITES tells the libjson engine to escape special character | |
| | | s when it writes | |
| | | * out. If this option is turned off, the json it outputs may not adhere | |
| | | to JSON standards | |
| | | */ | |
| | | #define JSON_ESCAPE_WRITES | |
| | | | |
| | | /* | |
| | | * JSON_COMMENTS tells libjson to store and write comments. libjson alway | |
| | | s supports | |
| | | * parsing json that has comments in it as it simply ignores them, but wit | |
| | | h this option | |
| | | * it keeps the comments and allows you to insert further comments | |
| | | */ | |
| | | //#define JSON_COMMENTS | |
| | | | |
| | | /* | |
| * JSON_WRITE_BASH_COMMENTS will cause libjson to write all comments in ba
sh (#) style | | * JSON_WRITE_BASH_COMMENTS will cause libjson to write all comments in ba
sh (#) style | |
| * if this option is not turned on, then it will use C-style comments. Ba
sh comments are | | * if this option is not turned on, then it will use C-style comments. Ba
sh comments are | |
| * all single line | | * all single line | |
| */ | | */ | |
| //#define JSON_WRITE_BASH_COMMENTS | | //#define JSON_WRITE_BASH_COMMENTS | |
| | | | |
| /* | | /* | |
| * JSON_WRITE_SINGLE_LINE_COMMENTS will cause libjson to write all comment
s in using // | | * JSON_WRITE_SINGLE_LINE_COMMENTS will cause libjson to write all comment
s in using // | |
| * notation, or (#) if that option is on. Some parsers do not support mul
tiline C comments | | * notation, or (#) if that option is on. Some parsers do not support mul
tiline C comments | |
| * although, this option is not needed for bash comments, as they are all
single line anyway | | * although, this option is not needed for bash comments, as they are all
single line anyway | |
| */ | | */ | |
| //#define JSON_WRITE_SINGLE_LINE_COMMENTS | | //#define JSON_WRITE_SINGLE_LINE_COMMENTS | |
| | | | |
| /* | | /* | |
| * JSON_VALIDATE turns on validation features of libjson. This option req
uires JSON_SAFE | | * JSON_VALIDATE turns on validation features of libjson. This option req
uires JSON_SAFE | |
| */ | | */ | |
|
| #define JSON_VALIDATE | | //#define JSON_VALIDATE | |
| | | | |
| /* | | /* | |
| * JSON_CASE_INSENSITIVE_FUNCTIONS turns on funtions for finding child nod
es in a case- | | * JSON_CASE_INSENSITIVE_FUNCTIONS turns on funtions for finding child nod
es in a case- | |
| * insenititve way | | * insenititve way | |
| */ | | */ | |
|
| #define JSON_CASE_INSENSITIVE_FUNCTIONS | | //#define JSON_CASE_INSENSITIVE_FUNCTIONS | |
| | | | |
| /* | | | |
| * JSON_UNIT_TEST is used to maintain and debug the libjson. It makes all | | | |
| private | | | |
| * members and functions public so that tests can do checks of the inner w | | | |
| orkings | | | |
| * of libjson. This should not be turned on by end users. | | | |
| */ | | | |
| //#define JSON_UNIT_TEST | | | |
| | | | |
| /* | | /* | |
| * JSON_INDEX_TYPE allows you th change the size type for the children fun
ctions. If this | | * JSON_INDEX_TYPE allows you th change the size type for the children fun
ctions. If this | |
| * option is not used then unsigned int is used. This option is useful fo
r cutting down | | * option is not used then unsigned int is used. This option is useful fo
r cutting down | |
| * on memory, or using huge numbers of child nodes (over 4 billion) | | * on memory, or using huge numbers of child nodes (over 4 billion) | |
| */ | | */ | |
| //#define JSON_INDEX_TYPE unsigned int | | //#define JSON_INDEX_TYPE unsigned int | |
| | | | |
|
| | | /* | |
| | | * JSON_STRING_HEADER allows you to change the type of string that libjson | |
| | | uses both for the | |
| | | * interface and internally. It must implement most of the STL string int | |
| | | erface, but not all | |
| | | * of it. Things like wxString or QString should wourk without much troub | |
| | | le | |
| | | */ | |
| | | //#define JSON_STRING_HEADER "../TestSuite/StringTest.h" | |
| | | | |
| | | /* | |
| | | * JSON_UNIT_TEST is used to maintain and debug the libjson. It makes all | |
| | | private | |
| | | * members and functions public so that tests can do checks of the inner w | |
| | | orkings | |
| | | * of libjson. This should not be turned on by end users. | |
| | | */ | |
| | | //#define JSON_UNIT_TEST | |
| | | | |
| #endif | | #endif | |
| | | | |
End of changes. 9 change blocks. |
| 25 lines changed or deleted | | 51 lines changed or added | |
|
| JSONWorker.h | | JSONWorker.h | |
| | | | |
| skipping to change at line 34 | | skipping to change at line 34 | |
| #define STRING_ENCODED this, false | | #define STRING_ENCODED this, false | |
| static json_string FixString(const json_string & value_t, const i
nternalJSONNode * flag, bool which); | | static json_string FixString(const json_string & value_t, const i
nternalJSONNode * flag, bool which); | |
| #else | | #else | |
| #define NAME_ENCODED _name_encoded | | #define NAME_ENCODED _name_encoded | |
| #define STRING_ENCODED _string_encoded | | #define STRING_ENCODED _string_encoded | |
| static json_string FixString(const json_string & value_t, bool &
flag); | | static json_string FixString(const json_string & value_t, bool &
flag); | |
| #endif | | #endif | |
| static json_string UnfixString(const json_string & value_t, bool flag); | | static json_string UnfixString(const json_string & value_t, bool flag); | |
| JSON_PRIVATE | | JSON_PRIVATE | |
| static json_char Hex(const json_char * & pos); | | static json_char Hex(const json_char * & pos); | |
|
| static unsigned json_char UTF8(const json_char * & pos); | | static json_uchar UTF8(const json_char * & pos); | |
| static json_string toUTF8(unsigned json_char p); | | #ifdef JSON_ESCAPE_WRITES | |
| | | static json_string toUTF8(json_uchar p); | |
| | | #endif | |
| #ifdef JSON_UNICODE | | #ifdef JSON_UNICODE | |
| static json_string UTF(const json_char * & pos); | | static json_string UTF(const json_char * & pos); | |
|
| static json_string toSurrogatePair(unsigned json_char pos); | | #ifdef JSON_ESCAPE_WRITES | |
| | | static json_string toSurrogatePair(json_uchar pos); | |
| | | #endif | |
| #endif | | #endif | |
| static void SpecialChar(const json_char * & pos, json_string & res); | | static void SpecialChar(const json_char * & pos, json_string & res); | |
| static size_t FindNextRelevant(json_char ch, const json_string & value_
t, const size_t pos); | | static size_t FindNextRelevant(json_char ch, const json_string & value_
t, const size_t pos); | |
| static void NewNode(const internalJSONNode * parent, const json_string
& name, const json_string & value, bool array); | | static void NewNode(const internalJSONNode * parent, const json_string
& name, const json_string & value, bool array); | |
| }; | | }; | |
| | | | |
| #endif | | #endif | |
| | | | |
End of changes. 2 change blocks. |
| 3 lines changed or deleted | | 7 lines changed or added | |
|
| NumberToString.h | | NumberToString.h | |
| #ifndef NUMBERTOSTRING_H | | #ifndef NUMBERTOSTRING_H | |
| #define NUMBERTOSTRING_H | | #define NUMBERTOSTRING_H | |
| | | | |
| #include "JSONDebug.h" | | #include "JSONDebug.h" | |
| #include "JSONMemory.h" | | #include "JSONMemory.h" | |
| #include <cstdio> | | #include <cstdio> | |
| | | | |
| template <unsigned int GETLENSIZE> | | template <unsigned int GETLENSIZE> | |
|
| struct getLenSize | | struct getLenSize{ | |
| { | | | |
| char tmp[GETLENSIZE == 16]; // compile time assertion | | char tmp[GETLENSIZE == 16]; // compile time assertion | |
| enum {GETLEN = 41}; | | enum {GETLEN = 41}; | |
| }; | | }; | |
| | | | |
| template<> | | template<> | |
|
| struct getLenSize<1> | | struct getLenSize<1>{ | |
| { | | | |
| enum {GETLEN = 5}; | | enum {GETLEN = 5}; | |
| }; | | }; | |
| | | | |
| template <> | | template <> | |
|
| struct getLenSize<2> | | struct getLenSize<2>{ | |
| { | | | |
| enum {GETLEN = 7}; | | enum {GETLEN = 7}; | |
| }; | | }; | |
| | | | |
| template <> | | template <> | |
|
| struct getLenSize<4> | | struct getLenSize<4>{ | |
| { | | | |
| enum {GETLEN = 12}; | | enum {GETLEN = 12}; | |
| }; | | }; | |
| | | | |
| template <> | | template <> | |
|
| struct getLenSize<8> | | struct getLenSize<8>{ | |
| { | | | |
| enum {GETLEN = 22}; | | enum {GETLEN = 22}; | |
| }; | | }; | |
| | | | |
| class NumberToString { | | class NumberToString { | |
| public: | | public: | |
| template<typename T> | | template<typename T> | |
| static json_string _itoa(T val){ | | static json_string _itoa(T val){ | |
|
| long value = (long)val; | | | |
| json_char result[getLenSize<sizeof(T)>::GETLEN]; | | json_char result[getLenSize<sizeof(T)>::GETLEN]; | |
| result[getLenSize<sizeof(T)>::GETLEN - 1] = JSON_TEXT('\0'); //nu
ll terminator | | result[getLenSize<sizeof(T)>::GETLEN - 1] = JSON_TEXT('\0'); //nu
ll terminator | |
| json_char * runner = &result[getLenSize<sizeof(T)>::GETLEN - 2]; | | json_char * runner = &result[getLenSize<sizeof(T)>::GETLEN - 2]; | |
| bool negative; | | bool negative; | |
| | | | |
|
| //first thing, check if it's negative, if so, make it positive | | START_MEM_SCOPE | |
| if (value < 0){ | | long value = (long)val; | |
| value = -value; | | //first thing, check if it's negative, if so, make it posi | |
| negative = true; | | tive | |
| } else { | | if (value < 0){ | |
| negative = false; | | value = -value; | |
| } | | negative = true; | |
| | | } else { | |
| | | negative = false; | |
| | | } | |
| | | | |
|
| //create the string | | //create the string | |
| do { | | do { | |
| *runner-- = (json_char)(value % 10) + JSON_TEXT('0'); | | *runner-- = (json_char)(value % 10) + JSON_TEXT('0' | |
| } while(value /= 10); | | ); | |
| | | } while(value /= 10); | |
| | | END_MEM_SCOPE | |
| | | | |
| //if it's negative, add the negation | | //if it's negative, add the negation | |
| json_string res; | | json_string res; | |
| if (negative){ | | if (negative){ | |
| *runner = JSON_TEXT('-'); | | *runner = JSON_TEXT('-'); | |
| res = runner; | | res = runner; | |
| } else { | | } else { | |
| res = runner + 1; | | res = runner + 1; | |
| } | | } | |
| return res; | | return res; | |
| } | | } | |
| | | | |
| #ifndef JSON_LIBRARY | | #ifndef JSON_LIBRARY | |
| template<typename T> | | template<typename T> | |
| static json_string _uitoa(T val){ | | static json_string _uitoa(T val){ | |
|
| unsigned long value = (unsigned long)val; | | | |
| json_char result[getLenSize<sizeof(T)>::GETLEN]; | | json_char result[getLenSize<sizeof(T)>::GETLEN]; | |
| result[getLenSize<sizeof(T)>::GETLEN - 1] = JSON_TEXT('\0'
); //null terminator | | result[getLenSize<sizeof(T)>::GETLEN - 1] = JSON_TEXT('\0'
); //null terminator | |
| json_char * runner = &result[getLenSize<sizeof(T)>::GETLEN
- 2]; | | json_char * runner = &result[getLenSize<sizeof(T)>::GETLEN
- 2]; | |
| | | | |
| //create the string | | //create the string | |
|
| do { | | START_MEM_SCOPE | |
| *runner-- = (json_char)(value % 10) + JSON_TEXT('0' | | unsigned long value = (unsigned long)val; | |
| ); | | do { | |
| } while(value /= 10); | | *runner-- = (json_char)(value % 10) + JSON_T | |
| | | EXT('0'); | |
| | | } while(value /= 10); | |
| | | END_MEM_SCOPE | |
| | | | |
| json_string res = runner + 1; | | json_string res = runner + 1; | |
| return res; | | return res; | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| template<typename T> | | template<typename T> | |
| static json_string _ftoa(T value){ | | static json_string _ftoa(T value){ | |
| json_char result[64]; | | json_char result[64]; | |
| #ifdef JSON_UNICODE | | #ifdef JSON_UNICODE | |
| swprintf(result, 63, L"%f", value); | | swprintf(result, 63, L"%f", value); | |
| #else | | #else | |
|
| snprintf(result, 63, "%f", value); | | //Thanks to Salvor Hardin for this Visual C++ fix | |
| | | #if _MSC_VER | |
| | | _snprintf_s(result, 63, 63, "%f", value); //yes, 63 | |
| | | appears twice using _snprintf_s() | |
| | | #else | |
| | | snprintf(result, 63, "%f", value); | |
| | | #endif | |
| #endif | | #endif | |
| //strip the trailing zeros | | //strip the trailing zeros | |
| for(json_char * pos = &result[0]; *pos; ++pos){ | | for(json_char * pos = &result[0]; *pos; ++pos){ | |
| if (*pos == '.'){ //only care about after the decimal | | if (*pos == '.'){ //only care about after the decimal | |
| for(json_char * runner = pos + 1; *runner; ++runner
){ | | for(json_char * runner = pos + 1; *runner; ++runner
){ | |
| if (*runner != JSON_TEXT('0')) pos = runner
+ 1; //have to go to the end 1.0001 | | if (*runner != JSON_TEXT('0')) pos = runner
+ 1; //have to go to the end 1.0001 | |
| } | | } | |
| *pos = JSON_TEXT('\0'); | | *pos = JSON_TEXT('\0'); | |
| break; | | break; | |
| } | | } | |
| | | | |
End of changes. 11 change blocks. |
| 28 lines changed or deleted | | 35 lines changed or added | |
|
| internalJSONNode.h | | internalJSONNode.h | |
| | | | |
| skipping to change at line 12 | | skipping to change at line 12 | |
| #define INTERNAL_JSONNODE_H | | #define INTERNAL_JSONNODE_H | |
| | | | |
| #include "JSONDebug.h" | | #include "JSONDebug.h" | |
| #include "JSONChildren.h" | | #include "JSONChildren.h" | |
| #include "JSONMemory.h" | | #include "JSONMemory.h" | |
| #ifdef JSON_DEBUG | | #ifdef JSON_DEBUG | |
| #include <climits> //to check int value | | #include <climits> //to check int value | |
| #endif | | #endif | |
| | | | |
| /* | | /* | |
|
| This class is the work horse of libJSON, it handles all of the | | This class is the work horse of libjson, it handles all of the | |
| functinality of JSONNode. This object is reference counted for | | functinality of JSONNode. This object is reference counted for | |
| speed and memory reasons. | | speed and memory reasons. | |
| | | | |
| If JSON_REF_COUNT is not on, this internal structure still has an impor
tant | | If JSON_REF_COUNT is not on, this internal structure still has an impor
tant | |
| purpose, as it can be passed around by JSONNoders that are flagged as t
emporary | | purpose, as it can be passed around by JSONNoders that are flagged as t
emporary | |
| */ | | */ | |
| | | | |
| class JSONNode; //forward declaration | | class JSONNode; //forward declaration | |
| | | | |
| #ifndef JSON_LIBRARY | | #ifndef JSON_LIBRARY | |
| | | | |
| skipping to change at line 104 | | skipping to change at line 104 | |
| | | | |
| #ifndef JSON_PREPARSE | | #ifndef JSON_PREPARSE | |
| void preparse(void); | | void preparse(void); | |
| #endif | | #endif | |
| | | | |
| #ifdef JSON_LIBRARY | | #ifdef JSON_LIBRARY | |
| void push_back(JSONNode * node); | | void push_back(JSONNode * node); | |
| #else | | #else | |
| void push_back(const JSONNode & node); | | void push_back(const JSONNode & node); | |
| #endif | | #endif | |
|
| void reserve(json_index_t size); | | void reserve(json_index_t siz); | |
| void push_front(const JSONNode & node); | | void push_front(const JSONNode & node); | |
| JSONNode * pop_back(json_index_t pos); | | JSONNode * pop_back(json_index_t pos); | |
| JSONNode * pop_back(const json_string & name_t); | | JSONNode * pop_back(const json_string & name_t); | |
| #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS | | #ifdef JSON_CASE_INSENSITIVE_FUNCTIONS | |
| JSONNode * pop_back_nocase(const json_string & name_t); | | JSONNode * pop_back_nocase(const json_string & name_t); | |
| #endif | | #endif | |
| | | | |
| JSONNode * at(json_index_t pos); | | JSONNode * at(json_index_t pos); | |
| //These return ** because pop_back needs them | | //These return ** because pop_back needs them | |
| JSONNode ** at(const json_string & name_t); | | JSONNode ** at(const json_string & name_t); | |
| | | | |
| skipping to change at line 256 | | skipping to change at line 256 | |
| return Children.size(); | | return Children.size(); | |
| } | | } | |
| | | | |
| inline bool internalJSONNode::empty(void) const { | | inline bool internalJSONNode::empty(void) const { | |
| if (type() != JSON_NODE && type() != JSON_ARRAY) return true; | | if (type() != JSON_NODE && type() != JSON_ARRAY) return true; | |
| Fetch(); | | Fetch(); | |
| return Children.empty(); | | return Children.empty(); | |
| } | | } | |
| | | | |
| inline unsigned char internalJSONNode::type(void) const { | | inline unsigned char internalJSONNode::type(void) const { | |
|
| #ifdef JSON_LESS_MEMORY | | return _type; | |
| return _type & 0xF; | | | |
| #else | | | |
| return _type; | | | |
| #endif | | | |
| } | | } | |
| | | | |
| inline json_string internalJSONNode::name(void) const { | | inline json_string internalJSONNode::name(void) const { | |
| return _name; | | return _name; | |
| } | | } | |
| | | | |
| inline void internalJSONNode::setname(const json_string & newname){ | | inline void internalJSONNode::setname(const json_string & newname){ | |
|
| _name = newname; | | | |
| #ifdef JSON_LESS_MEMORY | | #ifdef JSON_LESS_MEMORY | |
|
| _type |= 0x10; | | JSON_ASSERT(newname.capacity() == newname.length(), JSON_TEXT("na | |
| #else | | me object too large")); | |
| _name_encoded = true; | | | |
| #endif | | #endif | |
|
| | | _name = newname; | |
| | | _name_encoded = true; | |
| } | | } | |
| | | | |
| #ifdef JSON_COMMENTS | | #ifdef JSON_COMMENTS | |
| inline void internalJSONNode::setcomment(const json_string & comment){ | | inline void internalJSONNode::setcomment(const json_string & comment){ | |
|
| | | #ifdef JSON_LESS_MEMORY | |
| | | JSON_ASSERT(comment.capacity() == comment.length(), JSON_T | |
| | | EXT("comment object too large")); | |
| | | #endif | |
| _comment = comment; | | _comment = comment; | |
| } | | } | |
| | | | |
| inline json_string internalJSONNode::getcomment(void) const { | | inline json_string internalJSONNode::getcomment(void) const { | |
| return _comment; | | return _comment; | |
| } | | } | |
| #endif | | #endif | |
| | | | |
| inline json_string internalJSONNode::as_string(void) const { | | inline json_string internalJSONNode::as_string(void) const { | |
| Fetch(); | | Fetch(); | |
| | | | |
| skipping to change at line 402 | | skipping to change at line 400 | |
| inline JSONNode ** internalJSONNode::end(void) const { | | inline JSONNode ** internalJSONNode::end(void) const { | |
| Fetch(); | | Fetch(); | |
| return Children.end(); | | return Children.end(); | |
| } | | } | |
| | | | |
| inline JSONNode * internalJSONNode::at(json_index_t pos){ | | inline JSONNode * internalJSONNode::at(json_index_t pos){ | |
| Fetch(); | | Fetch(); | |
| return Children[pos]; | | return Children[pos]; | |
| } | | } | |
| | | | |
|
| inline void internalJSONNode::reserve(json_index_t size){ | | inline void internalJSONNode::reserve(json_index_t siz){ | |
| Fetch(); | | Fetch(); | |
|
| Children.reserve2(size); | | Children.reserve2(siz); | |
| } | | } | |
| | | | |
| /* | | /* | |
| These functions are to allow allocation to be completely controlled by
the callbacks | | These functions are to allow allocation to be completely controlled by
the callbacks | |
| */ | | */ | |
| | | | |
| inline void internalJSONNode::deleteInternal(internalJSONNode * ptr){ | | inline void internalJSONNode::deleteInternal(internalJSONNode * ptr){ | |
| #ifdef JSON_MEMORY_CALLBACKS | | #ifdef JSON_MEMORY_CALLBACKS | |
| ptr -> ~internalJSONNode(); | | ptr -> ~internalJSONNode(); | |
| libjson_free<internalJSONNode>(ptr); | | libjson_free<internalJSONNode>(ptr); | |
| | | | |
End of changes. 9 change blocks. |
| 13 lines changed or deleted | | 13 lines changed or added | |
|