JSONChildren.h   JSONChildren.h 
skipping to change at line 139 skipping to change at line 139
return array; return array;
} }
//returns the end of the array //returns the end of the array
inline JSONNode ** end(void) const json_nothrow { inline JSONNode ** end(void) const json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null end")); JSON_ASSERT(this != 0, JSON_TEXT("Children is null end"));
return array + mysize; return array + mysize;
} }
//makes sure that even after shirnking and expanding, the iterator is i n same relative position //makes sure that even after shirnking and expanding, the iterator is i n same relative position
template <bool reverse>
struct iteratorKeeper { struct iteratorKeeper {
public: public:
#ifdef JSON_LIBRARY iteratorKeeper(jsonChildren * pthis, JSONNode ** & position) json_
iteratorKeeper(jsonChildren * pthis, JSONNode ** & positio nothrow :
n) json_nothrow : myRelativeOffset(reverse ? (json_index_t)(pthis -> array +
myRelativeOffset((json_index_t)(position - pthis -> (size_t)pthis -> mysize - position) : (json_index_t)(position - pthis -> ar
array)), ray)),
#else myChildren(pthis),
iteratorKeeper(jsonChildren * pthis, JSONNode ** & positio myPos(position){}
n, bool reverse = false) json_nothrow :
myRelativeOffset(reverse ? (json_index_t)(pthis ->
array + (size_t)pthis -> mysize - position) : (json_index_t)(position - pth
is -> array)),
myReverse(reverse),
#endif
myChildren(pthis),
myPos(position){}
~iteratorKeeper(void) json_nothrow { ~iteratorKeeper(void) json_nothrow {
#ifdef JSON_LIBRARY if (reverse){
myPos = myChildren -> array + myRelativeOffset; myPos = myChildren -> array + myChildren -> mysize -
#else myRelativeOffset;
if (json_unlikely(myReverse)){ } else {
myPos = myChildren -> array + myChildren -> myPos = myChildren -> array + myRelativeOffset;
mysize - myRelativeOffset; }
} else {
myPos = myChildren -> array + myRelativeOffs
et;
}
#endif
} }
private: private:
iteratorKeeper(const iteratorKeeper &); iteratorKeeper(const iteratorKeeper &);
iteratorKeeper & operator = (const iteratorKeeper &); iteratorKeeper & operator = (const iteratorKeeper &);
json_index_t myRelativeOffset; json_index_t myRelativeOffset;
jsonChildren * myChildren; jsonChildren * myChildren;
JSONNode ** & myPos; JSONNode ** & myPos;
#ifndef JSON_LIBRARY
bool myReverse BITS(1);
#endif
}; };
//This function DOES NOT delete the item it points to //This function DOES NOT delete the item it points to
inline void erase(JSONNode ** & position) json_nothrow { inline void erase(JSONNode ** & position) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null erase")); JSON_ASSERT(this != 0, JSON_TEXT("Children is null erase"));
JSON_ASSERT(array != 0, JSON_TEXT("erasing something from a null array 1")); JSON_ASSERT(array != 0, JSON_TEXT("erasing something from a null array 1"));
JSON_ASSERT(position >= array, JSON_TEXT("position is beneath the start of the array 1")); JSON_ASSERT(position >= array, JSON_TEXT("position is beneath the start of the array 1"));
JSON_ASSERT(position <= array + mysize, JSON_TEXT("erasing out of bounds 1")); JSON_ASSERT(position <= array + mysize, JSON_TEXT("erasing out of bounds 1"));
std::memmove(position, position + 1, (mysize-- - (position - arra y) - 1) * sizeof(JSONNode *)); std::memmove(position, position + 1, (mysize-- - (position - arra y) - 1) * sizeof(JSONNode *));
iteratorKeeper ik(this, position); iteratorKeeper<false> ik(this, position);
shrink(); shrink();
} }
//This function DOES NOT delete the item it points to //This function DOES NOT delete the item it points to
inline void erase(JSONNode ** & position, json_index_t number) json_not hrow { inline void erase(JSONNode ** & position, json_index_t number) json_not hrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null erase 2")); JSON_ASSERT(this != 0, JSON_TEXT("Children is null erase 2"));
doerase(position, number); doerase(position, number);
iteratorKeeper ik(this, position); iteratorKeeper<false> ik(this, position);
shrink(); shrink();
} }
//This function DOES NOT delete the item it points to //This function DOES NOT delete the item it points to
inline void erase(JSONNode ** position, json_index_t number, JSONNode * * & starter) json_nothrow { inline void erase(JSONNode ** position, json_index_t number, JSONNode * * & starter) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null erase 3")); JSON_ASSERT(this != 0, JSON_TEXT("Children is null erase 3"));
doerase(position, number); doerase(position, number);
iteratorKeeper ik(this, starter); iteratorKeeper<false> ik(this, starter);
shrink(); shrink();
} }
#ifdef JSON_LIBRARY #ifdef JSON_LIBRARY
void insert(JSONNode ** & position, JSONNode * item) json_nothrow { void insert(JSONNode ** & position, JSONNode * item) json_nothrow {
#else #else
void insert(JSONNode ** & position, JSONNode * item, bool reverse = false) json_nothrow { void insert(JSONNode ** & position, JSONNode * item, bool reverse = false) json_nothrow {
#endif #endif
JSON_ASSERT(this != 0, JSON_TEXT("Children is null insert")); JSON_ASSERT(this != 0, JSON_TEXT("Children is null insert"));
//position isnt relative to array because of realloc //position isnt relative to array because of realloc
JSON_ASSERT(position >= array, JSON_TEXT("position is beneath the start of the array insert 1")); JSON_ASSERT(position >= array, JSON_TEXT("position is beneath the start of the array insert 1"));
JSON_ASSERT(position <= array + mysize, JSON_TEXT("position is ab ove the end of the array insert 1")); JSON_ASSERT(position <= array + mysize, JSON_TEXT("position is ab ove the end of the array insert 1"));
{ #ifndef JSON_LIBRARY
#ifdef JSON_LIBRARY if (reverse){
iteratorKeeper ik(this, position); iteratorKeeper<true> ik(this, position);
#else inc();
iteratorKeeper ik(this, position, reverse); } else
#endif #endif
inc(); {
} iteratorKeeper<false> ik(this, position);
inc();
}
std::memmove(position + 1, position, (mysize++ - (position - arra y)) * sizeof(JSONNode *)); std::memmove(position + 1, position, (mysize++ - (position - arra y)) * sizeof(JSONNode *));
*position = item; *position = item;
} }
void insert(JSONNode ** & position, JSONNode ** items, json_index_t num ) json_nothrow { void insert(JSONNode ** & position, JSONNode ** items, json_index_t num ) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null insert 2")); JSON_ASSERT(this != 0, JSON_TEXT("Children is null insert 2"));
JSON_ASSERT(position >= array, JSON_TEXT("position is beneath the start of the array insert 2")); JSON_ASSERT(position >= array, JSON_TEXT("position is beneath the start of the array insert 2"));
JSON_ASSERT(position <= array + mysize, JSON_TEXT("position is ab ove the end of the array insert 2")); JSON_ASSERT(position <= array + mysize, JSON_TEXT("position is ab ove the end of the array insert 2"));
{ {
iteratorKeeper ik(this, position); iteratorKeeper<false> ik(this, position);
inc(num); inc(num);
} }
const size_t ptrs = ((JSONNode **)(array + mysize)) - position; const size_t ptrs = ((JSONNode **)(array + mysize)) - position;
std::memmove(position + num, position, ptrs * sizeof(JSONNode *)) ; std::memmove(position + num, position, ptrs * sizeof(JSONNode *)) ;
std::memcpy(position, items, num * sizeof(JSONNode *)); std::memcpy(position, items, num * sizeof(JSONNode *));
mysize += num; mysize += num;
} }
inline void reserve(json_index_t amount) json_nothrow { inline void reserve(json_index_t amount) json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null reserve")); JSON_ASSERT(this != 0, JSON_TEXT("Children is null reserve"));
JSON_ASSERT(array == 0, JSON_TEXT("reserve is not meant to expand a preexisting array")); JSON_ASSERT(array == 0, JSON_TEXT("reserve is not meant to expand a preexisting array"));
JSON_ASSERT(mycapacity == 0, JSON_TEXT("reservec is not meant to expand a preexisting array")); JSON_ASSERT(mycapacity == 0, JSON_TEXT("reservec is not meant to expand a preexisting array"));
JSON_ASSERT(mysize == 0, JSON_TEXT("reserves is not meant to expa nd a preexisting array")); JSON_ASSERT(mysize == 0, JSON_TEXT("reserves is not meant to expa nd a preexisting array"));
array = json_malloc<JSONNode*>(mycapacity = amount); array = json_malloc<JSONNode*>(mycapacity = amount);
} }
//it is static because mine might change pointers entirely
static void reserve2(jsonChildren *& mine, json_index_t amount) json_no throw; static void reserve2(jsonChildren *& mine, json_index_t amount) json_no throw;
//shrinks the array to only as large as it needs to be to hold everythi ng within it //shrinks the array to only as large as it needs to be to hold everythi ng within it
inline childrenVirtual void shrink() json_nothrow { inline childrenVirtual void shrink() json_nothrow {
JSON_ASSERT(this != 0, JSON_TEXT("Children is null shrink")); JSON_ASSERT(this != 0, JSON_TEXT("Children is null shrink"));
if (json_unlikely(mysize == 0)){ //size is zero, we should compl etely free the array if (json_unlikely(mysize == 0)){ //size is zero, we should compl etely free the array
libjson_free<JSONNode*>(array); //free does checks for a null pointer, so don't bother checking libjson_free<JSONNode*>(array); //free does checks for a null pointer, so don't bother checking
array = 0; array = 0;
#ifdef JSON_LESS_MEMORY #ifdef JSON_LESS_MEMORY
} else { //need to shrink it, using realloc } else { //need to shrink it, using realloc
 End of changes. 10 change blocks. 
41 lines changed or deleted 30 lines changed or added


 JSONDebug.h   JSONDebug.h 
skipping to change at line 57 skipping to change at line 57
} }
#else #else
#define JSON_ASSERT_SAFE(condition, msg, code) #define JSON_ASSERT_SAFE(condition, msg, code)
#define JSON_FAIL_SAFE(msg, code) #define JSON_FAIL_SAFE(msg, code)
#endif #endif
#define JSON_ASSERT(condition, msg) #define JSON_ASSERT(condition, msg)
#define JSON_FAIL(msg) #define JSON_FAIL(msg)
#endif #endif
#ifdef JSON_UNIT_TEST
#include <map>
#include <sstream>
#include <string>
class libjson_CodeCoverage {
public:
libjson_CodeCoverage(const std::string & desc, size_t branch
es);
~libjson_CodeCoverage(void);
static void inc(libjson_CodeCoverage * cc, const std::string
& _id){
if (cc){
std::map<std::string, size_t>::iterator pos
= cc -> _ids.find(_id);
if (pos == cc -> _ids.end()){
cc -> _ids[_id] = 1;
} else {
++(*pos).second;
}
}
}
inline bool isComplete(){ return _ids.size() == _branches; }
static libjson_CodeCoverage * getByName(const std::string &
name);
std::string printOut(void){
std::stringstream output;
#ifndef JSON_DEBUG
if (!isComplete()){
#endif
output << "Hit these coverage markers: <tabl
e border=\"1\">";
std::map<std::string, size_t>::iterator pos
= _ids.begin();
for(; pos != _ids.end(); ++pos){
output << "<tr><td>" << (*pos).first
<< "</td>";
output << "<td>" << (*pos).second <<
"</td></tr>";
}
output << "</table>";
#ifndef JSON_DEBUG
}
#endif
output << ((float)(_ids.size()) / (float)(_branches)
) * 100.0 << "% complete";
return output.str();
}
protected:
libjson_CodeCoverage(const libjson_CodeCoverage & );
size_t _branches;
std::string _desc;
std::map<std::string, size_t> _ids;
};
#define ScopeCoverageHeap(desc, branches)\
coverage = new libjson_CodeCoverage(#desc, branches);\
assertNotNull(GetScopeCoverage(desc))
#define ScopeCoverage(desc, branches)\
libjson_CodeCoverage desc(#desc, branches);\
assertNotNull(GetScopeCoverage(desc))
#define HitScopeCoverage(name, id)\
libjson_CodeCoverage::inc(GetScopeCoverage(name), #id)
#define GetScopeCoverage(name)\
libjson_CodeCoverage::getByName(std::string( #name ))
#define AssertScopeCoverage(desc)\
assertTrue(desc.isComplete());\
if (!desc.isComplete()){\
FAIL(desc.printOut());\
} else {\
PASS(desc.printOut());\
}
#define AssertScopeCoverageHeap(desc)\
assertTrue(coverage -> isComplete());\
if (!coverage -> isComplete()){\
FAIL(coverage -> printOut());\
} else {\
PASS(coverage -> printOut());\
}\
delete coverage;
#else
#define ScopeCoverageHeap(desc, branches) (void)0
#define ScopeCoverage(desc, branches) (void)0
#define HitScopeCoverage(name, id) (void)0
#define GetScopeCoverage(name, activate) (void)0
#define AssertScopeCoverage(desc) (void)0
#define AssertScopeCoverageHeap(desc) (void)0
#endif
#endif #endif
 End of changes. 1 change blocks. 
88 lines changed or deleted 0 lines changed or added


 JSONDefs.h   JSONDefs.h 
skipping to change at line 17 skipping to change at line 17
the library instead of linking. the library instead of linking.
*/ */
#include "../JSONOptions.h" #include "../JSONOptions.h"
#include "JSONDefs/Unknown_C.h" #include "JSONDefs/Unknown_C.h"
#include "JSONDefs/GNU_C.h" #include "JSONDefs/GNU_C.h"
#include "JSONDefs/Visual_C.h" #include "JSONDefs/Visual_C.h"
#include "JSONDefs/Strings_Defs.h" #include "JSONDefs/Strings_Defs.h"
#define __LIBJSON_MAJOR__ 7 #define __LIBJSON_MAJOR__ 7
#define __LIBJSON_MINOR__ 5 #define __LIBJSON_MINOR__ 6
#define __LIBJSON_PATCH__ 1 #define __LIBJSON_PATCH__ 0
#define __LIBJSON_VERSION__ (__LIBJSON_MAJOR__ * 10000 + __LIBJSON_MINOR__ * 100 + __LIBJSON_PATCH__) #define __LIBJSON_VERSION__ (__LIBJSON_MAJOR__ * 10000 + __LIBJSON_MINOR__ * 100 + __LIBJSON_PATCH__)
#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
skipping to change at line 78 skipping to change at line 78
#endif #endif
#else #else
#ifdef __GNUC__ #ifdef __GNUC__
#ifdef __STRICT_ANSI__ #ifdef __STRICT_ANSI__
#warning, Using -ansi GCC option, but JSON_ISO_STRICT not on, turning it on for you #warning, Using -ansi GCC option, but JSON_ISO_STRICT not on, turning it on for you
#define JSON_ISO_STRICT #define JSON_ISO_STRICT
#endif #endif
#endif #endif
#endif #endif
#ifdef JSON_NUMBER_TYPE
typedef JSON_NUMBER_TYPE json_number
#define JSON_FLOAT_THRESHHOLD 0.00001
#else
#ifdef JSON_LESS_MEMORY
typedef float json_number;
#define JSON_FLOAT_THRESHHOLD 0.00001f
#else
typedef double json_number;
#define JSON_FLOAT_THRESHHOLD 0.00001
#endif
#endif
#ifdef JSON_LESS_MEMORY #ifdef JSON_LESS_MEMORY
/* PACKED and BITS stored in compiler specific headers */ /* PACKED and BITS stored in compiler specific headers */
#define START_MEM_SCOPE { #define START_MEM_SCOPE {
#define END_MEM_SCOPE } #define END_MEM_SCOPE }
typedef float json_number;
#define JSON_FLOAT_THRESHHOLD 0.00001f
#else #else
#define PACKED(x) #define PACKED(x)
#define BITS(x) #define BITS(x)
#define START_MEM_SCOPE #define START_MEM_SCOPE
#define END_MEM_SCOPE #define END_MEM_SCOPE
//#ifdef JSON_ISO_STRICT
typedef double json_number;
//#else
//typedef long double json_number;
//#endif
#define JSON_FLOAT_THRESHHOLD 0.00001
#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. 4 change blocks. 
10 lines changed or deleted 15 lines changed or added


 JSONMemory.h   JSONMemory.h 
skipping to change at line 18 skipping to change at line 18
#if defined(JSON_DEBUG) || defined(JSON_SAFE) #if defined(JSON_DEBUG) || defined(JSON_SAFE)
#define JSON_FREE_PASSTYPE & #define JSON_FREE_PASSTYPE &
#else #else
#define JSON_FREE_PASSTYPE #define JSON_FREE_PASSTYPE
#endif #endif
#if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL) #if defined(JSON_MEMORY_CALLBACKS) || defined(JSON_MEMORY_POOL)
class JSONMemory { class JSONMemory {
public: public:
#ifdef __GNUC__
static void * json_malloc(size_t siz) json_malloc_attr; static void * json_malloc(size_t siz) json_malloc_attr;
static void * json_realloc(void * ptr, size_t siz) json_malloc _attr; static void * json_realloc(void * ptr, size_t siz) json_malloc _attr;
#else
static void * json_malloc(size_t siz) json_nothrow;
static void * json_realloc(void * ptr, size_t siz) json_no
throw;
#endif
static void json_free(void * ptr) json_nothrow; static void json_free(void * ptr) json_nothrow;
static void registerMemoryCallbacks(json_malloc_t mal, json_reall oc_t real, json_free_t fre) json_nothrow json_cold; static void registerMemoryCallbacks(json_malloc_t mal, json_reall oc_t real, json_free_t fre) json_nothrow json_cold;
private:
JSONMemory(void);
}; };
template <typename T> static inline T * json_malloc(size_t count) json_ malloc_attr; template <typename T> static inline T * json_malloc(size_t count) json_ malloc_attr;
template <typename T> static inline T * json_malloc(size_t count) json_ nothrow { template <typename T> static inline T * json_malloc(size_t count) json_ nothrow {
return (T *)JSONMemory::json_malloc(sizeof(T) * count); return (T *)JSONMemory::json_malloc(sizeof(T) * count);
} }
template <typename T> static inline T * json_realloc(T * ptr, size_t co unt) json_malloc_attr; template <typename T> static inline T * json_realloc(T * ptr, size_t co unt) json_malloc_attr;
template <typename T> static inline T * json_realloc(T * ptr, size_t co unt) json_nothrow { template <typename T> static inline T * json_realloc(T * ptr, size_t co unt) json_nothrow {
return (T *)JSONMemory::json_realloc(ptr, sizeof(T) * count); return (T *)JSONMemory::json_realloc(ptr, sizeof(T) * count);
skipping to change at line 84 skipping to change at line 81
#else #else
return (T *)std::realloc(ptr, count * sizeof(T)); return (T *)std::realloc(ptr, count * sizeof(T));
#endif #endif
} }
#endif #endif
#ifdef JSON_MEMORY_MANAGE #ifdef JSON_MEMORY_MANAGE
#include <map> #include <map>
class JSONNode; class JSONNode;
struct auto_expand { struct auto_expand {
public:
auto_expand(void) json_nothrow : mymap(){} auto_expand(void) json_nothrow : mymap(){}
~auto_expand(void) json_nothrow { purge(); } ~auto_expand(void) json_nothrow { purge(); }
void purge(void) json_nothrow; void purge(void) json_nothrow;
inline void clear(void) json_nothrow { purge(); mymap.clear(); } inline void clear(void) json_nothrow { purge(); mymap.clear(); }
inline void * insert(void * ptr) json_nothrow { mymap[ptr] = ptr; return ptr; } inline void * insert(void * ptr) json_nothrow { mymap[ptr] = ptr; return ptr; }
inline void remove(void * ptr) json_nothrow { inline void remove(void * ptr) json_nothrow {
JSON_MAP(void *, void *)::iterator i = mymap.find(ptr); JSON_MAP(void *, void *)::iterator i = mymap.find(ptr);
JSON_ASSERT(i != mymap.end(), JSON_TEXT("Removing a non-ma naged item")); JSON_ASSERT(i != mymap.end(), JSON_TEXT("Removing a non-ma naged item"));
mymap.erase(i); mymap.erase(i);
} }
JSON_MAP(void *, void *) mymap; JSON_MAP(void *, void *) mymap;
private:
auto_expand(const auto_expand &);
auto_expand & operator = (const auto_expand &);
}; };
struct auto_expand_node { struct auto_expand_node {
public:
auto_expand_node(void) json_nothrow : mymap(){} auto_expand_node(void) json_nothrow : mymap(){}
~auto_expand_node(void) json_nothrow { purge(); } ~auto_expand_node(void) json_nothrow { purge(); }
void purge(void) json_nothrow ; void purge(void) json_nothrow ;
inline void clear(void) json_nothrow { purge(); mymap.clear(); } inline void clear(void) json_nothrow { purge(); mymap.clear(); }
inline JSONNode * insert(JSONNode * ptr) json_nothrow { mymap[ptr ] = ptr; return ptr; } inline JSONNode * insert(JSONNode * ptr) json_nothrow { mymap[ptr ] = ptr; return ptr; }
inline void remove(void * ptr) json_nothrow { inline void remove(void * ptr) json_nothrow {
JSON_MAP(void *, JSONNode *)::iterator i = mymap.find(ptr) ; JSON_MAP(void *, JSONNode *)::iterator i = mymap.find(ptr) ;
if(json_likely(i != mymap.end())) mymap.erase(i); if(json_likely(i != mymap.end())) mymap.erase(i);
} }
JSON_MAP(void *, JSONNode *) mymap; JSON_MAP(void *, JSONNode *) mymap;
private:
auto_expand_node(const auto_expand_node &);
auto_expand_node & operator = (const auto_expand_node &);
}; };
#ifdef JSON_STREAM #ifdef JSON_STREAM
class JSONStream; class JSONStream;
struct auto_expand_stream { struct auto_expand_stream {
public:
auto_expand_stream(void) json_nothrow : mymap(){} auto_expand_stream(void) json_nothrow : mymap(){}
~auto_expand_stream(void) json_nothrow { purge(); } ~auto_expand_stream(void) json_nothrow { purge(); }
void purge(void) json_nothrow ; void purge(void) json_nothrow ;
inline void clear(void) json_nothrow { purge(); mymap.clea r(); } inline void clear(void) json_nothrow { purge(); mymap.clea r(); }
inline JSONStream * insert(JSONStream * ptr) json_nothrow { mymap[ptr] = ptr; return ptr; } inline JSONStream * insert(JSONStream * ptr) json_nothrow { mymap[ptr] = ptr; return ptr; }
inline void remove(void * ptr) json_nothrow { inline void remove(void * ptr) json_nothrow {
JSON_MAP(void *, JSONStream *)::iterator i = mymap. find(ptr); JSON_MAP(void *, JSONStream *)::iterator i = mymap. find(ptr);
if(json_likely(i != mymap.end())) mymap.erase(i); if(json_likely(i != mymap.end())) mymap.erase(i);
} }
JSON_MAP(void *, JSONStream *) mymap; JSON_MAP(void *, JSONStream *) mymap;
private:
auto_expand_stream(const auto_expand_stream &);
auto_expand_stream & operator = (const auto_expand_stream &);
}; };
#endif #endif
#endif #endif
//The C++ way, use an self-deleting pointer and let the optimizer decide wh en it gets destroyed //The C++ way, use an self-deleting pointer and let the optimizer decide wh en it gets destroyed
template <typename T> template <typename T>
class json_auto { class json_auto {
public: public:
json_auto(void) json_nothrow : ptr(0){} json_auto(void) json_nothrow : ptr(0){}
json_auto(size_t count) json_nothrow : ptr(json_malloc<T>(count)) {} json_auto(size_t count) json_nothrow : ptr(json_malloc<T>(count)) {}
skipping to change at line 156 skipping to change at line 165
//Clears a string, if required, frees the memory //Clears a string, if required, frees the memory
static inline void clearString(json_string & str) json_nothrow { static inline void clearString(json_string & str) json_nothrow {
#ifdef JSON_LESS_MEMORY #ifdef JSON_LESS_MEMORY
json_string().swap(str); json_string().swap(str);
#else #else
str.clear(); str.clear();
#endif #endif
} }
//Shrinks a string //Shrinks a string
#ifdef JSON_LESS_MEMORY static inline void shrinkString(json_string & str) json_nothrow {
static inline json_string shrinkString(const json_string & str) json_no #ifdef JSON_LESS_MEMORY
throw { if (str.capacity() != str.length()) str = json_string(str.begin(),
if (str.capacity() == str.length()) return str; str.end());
return json_string(str.c_str()); #endif
} }
#else
#define shrinkString(str) str
#endif
#endif #endif
 End of changes. 10 change blocks. 
15 lines changed or deleted 20 lines changed or added


 JSONMemoryPool.h   JSONMemoryPool.h 
#ifndef JSON_MEMORY_POOL_H #ifndef JSON_MEMORY_POOL_H
#define JSON_MEMORY_POOL_H #define JSON_MEMORY_POOL_H
#ifdef JSON_MEMORY_POOL #ifdef JSON_MEMORY_POOL
#include "../mempool++/mempool.h" #include "../Dependencies/mempool++/mempool.h"
//this macro expands to the number of bytes a pool gets based on block size and number of 32s of the total pool it gets //this macro expands to the number of bytes a pool gets based on block size and number of 32s of the total pool it gets
#define jsonPoolPart(bytes_per_block, thirty_seconds_of_mem) bytes_per_bloc k, ((thirty_seconds_of_mem * JSON_MEMORY_POOL / 32) / bytes_per_block) #define jsonPoolPart(bytes_per_block, thirty_seconds_of_mem) bytes_per_bloc k, ((thirty_seconds_of_mem * JSON_MEMORY_POOL / 32) / bytes_per_block)
#ifdef JSON_PREPARSE #ifdef JSON_PREPARSE
#define NODEPOOL jsonPoolPart(sizeof(JSONNode), 1) #define NODEPOOL jsonPoolPart(sizeof(JSONNode), 1)
#define INTERNALNODEPOOL jsonPoolPart(sizeof(internalJSONNode), 3) #define INTERNALNODEPOOL jsonPoolPart(sizeof(internalJSONNode), 3)
#define MEMPOOL_1 jsonPoolPart(8, 2) #define MEMPOOL_1 jsonPoolPart(8, 2)
#define MEMPOOL_2 jsonPoolPart(16, 2) #define MEMPOOL_2 jsonPoolPart(16, 2)
#define MEMPOOL_3 jsonPoolPart(32, 2) #define MEMPOOL_3 jsonPoolPart(32, 2)
 End of changes. 1 change blocks. 
1 lines changed or deleted 1 lines changed or added


 JSONOptions.h   JSONOptions.h 
skipping to change at line 84 skipping to change at line 84
/* /*
* JSON_REF_COUNT causes libjson to reference count JSONNodes, which makes copying * JSON_REF_COUNT causes libjson to reference count JSONNodes, which makes copying
* and passing them around much faster. It is recommended that this stay on for * and passing them around much faster. It is recommended that this stay on for
* most uses * most uses
*/ */
#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 off, no base64 support is included
*/ */
#define JSON_BINARY #define JSON_BINARY
/* /*
* JSON_EXPOSE_BASE64 is used to turn on the functionality of libjson's ba se64 encoding * JSON_EXPOSE_BASE64 is used to turn on the functionality of libjson's ba se64 encoding
* and decoding. This may be useful if you want to obfuscate your json, o r send binary data over * and decoding. This may be useful if you want to obfuscate your json, o r send binary data over
* a network * a network
*/ */
#define JSON_EXPOSE_BASE64 #define JSON_EXPOSE_BASE64
skipping to change at line 254 skipping to change at line 254
*/ */
//#define JSON_BOOL_TYPE char //#define JSON_BOOL_TYPE char
/* /*
* JSON_INT_TYPE lets you change the int type for as_int. If you ommit th is option, the default * JSON_INT_TYPE lets you change the int type for as_int. If you ommit th is option, the default
* long will be used * long will be used
*/ */
//#define JSON_INT_TYPE long //#define JSON_INT_TYPE long
/* /*
* JSON_NUMBER_TYPE lets you change the number type for as_float as well a
s the internal storage for the
* number. If you omit this option, the default double will be used fo
r most cases and float for JSON_LESS_MEMORY
*/
//#define JSON_NUMBER_TYPE double
/*
* JSON_STRING_HEADER allows you to change the type of string that libjson uses both for the * 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 * 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 * of it. Things like wxString or QString should wourk without much troub le
*/ */
//#define JSON_STRING_HEADER "../TestSuite/StringTest.h" //#define JSON_STRING_HEADER "../TestSuite/StringTest.h"
/* /*
* JSON_UNIT_TEST is used to maintain and debug the libjson. It makes all private * 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 * 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. * of libjson. This should not be turned on by end users.
 End of changes. 2 change blocks. 
1 lines changed or deleted 9 lines changed or added


 JSONSharedString.h   JSONSharedString.h 
skipping to change at line 16 skipping to change at line 16
* Since libjson is a parser, it does a lot of substrings, but since * Since libjson is a parser, it does a lot of substrings, but since
* a string with all of the information already exists, those substring s * a string with all of the information already exists, those substring s
* can be infered by an offset and length and a pointer to the master * can be infered by an offset and length and a pointer to the master
* string * string
* *
* EXPERIMENTAL, Not used yet * EXPERIMENTAL, Not used yet
*/ */
#include "JSONDebug.h" #include "JSONDebug.h"
#include "JSONGlobals.h" #include "JSONGlobals.h"
#include "JSONMemory.h"
/*
mallocs: 3351
frees: 3351
reallocs: 3
bytes: 298751 (291 KB)
max bytes at once: 3624 (3 KB)
avg bytes at once: 970 (0 KB)
*/
#ifdef JSON_LESS_MEMORY #ifdef JSON_LESS_MEMORY
#ifdef __GNUC__ #ifdef __GNUC__
#pragma pack(push, 1) #pragma pack(push, 1)
#elif _MSC_VER #elif _MSC_VER
#pragma pack(push, json_shared_string_pack, 1) #pragma pack(push, json_shared_string_pack, 1)
#endif #endif
#endif #endif
class json_shared_string { class json_shared_string {
public: public:
inline json_string::iterator begin(void){
struct iterator;
struct const_iterator {
const_iterator(const json_char * p, const json_shared_string
* pa) : parent(pa), it(p){}
inline const_iterator& operator ++(void) json_nothrow { ++i
t; return *this; }
inline const_iterator& operator --(void) json_nothrow { --i
t; return *this; }
inline const_iterator& operator +=(long i) json_nothrow { i
t += i; return *this; }
inline const_iterator& operator -=(long i) json_nothrow { i
t -= i; return *this; }
inline const_iterator operator ++(int) json_nothrow {
const_iterator result(*this);
++it;
return result;
}
inline const_iterator operator --(int) json_nothrow {
const_iterator result(*this);
--it;
return result;
}
inline const_iterator operator +(long i) const json_nothrow
{
const_iterator result(*this);
result.it += i;
return result;
}
inline const_iterator operator -(long i) const json_nothrow
{
const_iterator result(*this);
result.it -= i;
return result;
}
inline const json_char & operator [](size_t pos) const json
_nothrow { return it[pos]; };
inline const json_char & operator *(void) const json_nothro
w { return *it; }
inline const json_char * operator ->(void) const json_nothr
ow { return it; }
inline bool operator == (const const_iterator & other) cons
t json_nothrow { return it == other.it; }
inline bool operator != (const const_iterator & other) cons
t json_nothrow { return it != other.it; }
inline bool operator > (const const_iterator & other) const
json_nothrow { return it > other.it; }
inline bool operator >= (const const_iterator & other) cons
t json_nothrow { return it >= other.it; }
inline bool operator < (const const_iterator & other) const
json_nothrow { return it < other.it; }
inline bool operator <= (const const_iterator & other) cons
t json_nothrow { return it <= other.it; }
inline bool operator == (const iterator & other) const json
_nothrow { return it == other.it; }
inline bool operator != (const iterator & other) const json
_nothrow { return it != other.it; }
inline bool operator > (const iterator & other) const json_
nothrow { return it > other.it; }
inline bool operator >= (const iterator & other) const json
_nothrow { return it >= other.it; }
inline bool operator < (const iterator & other) const json_
nothrow { return it < other.it; }
inline bool operator <= (const iterator & other) const json
_nothrow { return it <= other.it; }
inline const_iterator & operator =(const const_iterator & o
rig) json_nothrow { it = orig.it; return *this; }
const_iterator (const const_iterator & orig) json_nothrow :
it(orig.it) {}
private:
const json_shared_string * parent;
const json_char * it;
friend class json_shared_string;
friend struct iterator;
};
struct iterator {
iterator(const json_char * p, const json_shared_string * pa)
: parent(pa), it(p){}
inline iterator& operator ++(void) json_nothrow { ++it; ret
urn *this; }
inline iterator& operator --(void) json_nothrow { --it; ret
urn *this; }
inline iterator& operator +=(long i) json_nothrow { it += i
; return *this; }
inline iterator& operator -=(long i) json_nothrow { it -= i
; return *this; }
inline iterator operator ++(int) json_nothrow {
iterator result(*this);
++it;
return result;
}
inline iterator operator --(int) json_nothrow {
iterator result(*this);
--it;
return result;
}
inline iterator operator +(long i) const json_nothrow {
iterator result(*this);
result.it += i;
return result;
}
inline iterator operator -(long i) const json_nothrow {
iterator result(*this);
result.it -= i;
return result;
}
inline const json_char & operator [](size_t pos) const json
_nothrow { return it[pos]; };
inline const json_char & operator *(void) const json_nothro
w { return *it; }
inline const json_char * operator ->(void) const json_nothr
ow { return it; }
inline bool operator == (const const_iterator & other) cons
t json_nothrow { return it == other.it; }
inline bool operator != (const const_iterator & other) cons
t json_nothrow { return it != other.it; }
inline bool operator > (const const_iterator & other) const
json_nothrow { return it > other.it; }
inline bool operator >= (const const_iterator & other) cons
t json_nothrow { return it >= other.it; }
inline bool operator < (const const_iterator & other) const
json_nothrow { return it < other.it; }
inline bool operator <= (const const_iterator & other) cons
t json_nothrow { return it <= other.it; }
inline bool operator == (const iterator & other) const json
_nothrow { return it == other.it; }
inline bool operator != (const iterator & other) const json
_nothrow { return it != other.it; }
inline bool operator > (const iterator & other) const json_
nothrow { return it > other.it; }
inline bool operator >= (const iterator & other) const json
_nothrow { return it >= other.it; }
inline bool operator < (const iterator & other) const json_
nothrow { return it < other.it; }
inline bool operator <= (const iterator & other) const json
_nothrow { return it <= other.it; }
inline iterator & operator =(const iterator & orig) json_no
throw { it = orig.it; return *this; }
iterator (const iterator & orig) json_nothrow : it(orig.it)
{}
private:
const json_shared_string * parent;
const json_char * it;
friend class json_shared_string;
friend struct const_iterator;
};
inline json_shared_string::iterator begin(void){
iterator res = iterator(data(), this);
return res;
}
inline json_shared_string::iterator end(void){
iterator res = iterator(data() + len, this);
return res;
}
inline json_shared_string::const_iterator begin(void) const {
const_iterator res = const_iterator(data(), this);
return res;
}
inline json_shared_string::const_iterator end(void) const {
const_iterator res = const_iterator(data() + len, this);
return res;
}
inline json_string::iterator std_begin(void){
return _str -> mystring.begin() + offset; return _str -> mystring.begin() + offset;
} }
inline json_string::iterator end(void){ inline json_string::iterator std_end(void){
return begin() + len; return std_begin() + len;
} }
inline json_string::const_iterator begin(void) const{ inline json_string::const_iterator std_begin(void) const{
return _str -> mystring.begin() + offset; return _str -> mystring.begin() + offset;
} }
inline json_string::const_iterator end(void) const{ inline json_string::const_iterator std_end(void) const{
return begin() + len; return std_begin() + len;
} }
inline json_shared_string(void) : offset(0), len(0), _str(new json_s hared_string_internal(json_global(EMPTY_JSON_STRING))) {} inline json_shared_string(void) : offset(0), len(0), _str(new(json_m alloc<json_shared_string_internal>(1)) json_shared_string_internal(json_glo bal(EMPTY_JSON_STRING))) {}
inline json_shared_string(const json_string & str) : offset(0), len( str.length()), _str(new json_shared_string_internal(str)) {} inline json_shared_string(const json_string & str) : offset(0), len( str.length()), _str(new(json_malloc<json_shared_string_internal>(1)) json_s hared_string_internal(str)) {}
inline json_shared_string(const json_shared_string & str, size_t _of fset, size_t _len) : _str(str._str), offset(str.offset + _offset), len(_len ) { inline json_shared_string(const json_shared_string & str, size_t _of fset, size_t _len) : _str(str._str), offset(str.offset + _offset), len(_len ) {
++_str -> refCount; ++_str -> refCount;
} }
inline json_shared_string(const json_shared_string & str, size_t _of fset) : _str(str._str), offset(str.offset + _offset), len(str.len - _offset ) { inline json_shared_string(const json_shared_string & str, size_t _of fset) : _str(str._str), offset(str.offset + _offset), len(str.len - _offset ) {
++_str -> refCount; ++_str -> refCount;
} }
inline json_shared_string(const iterator & s, const iterator & e) :
_str(s.parent -> _str), offset(s.it - s.parent -> _str -> mystring.data()),
len(e.it - s.it){
++_str -> refCount;
}
inline ~json_shared_string(void){ inline ~json_shared_string(void){
deref(); deref();
} }
inline bool empty(void) const { return len == 0; } inline bool empty(void) const { return len == 0; }
size_t find(json_char ch, size_t pos = 0) const { size_t find(json_char ch, size_t pos = 0) const {
if (_str -> refCount == 1) return _str -> mystring.find(ch, pos); if (_str -> refCount == 1) return _str -> mystring.find(ch, pos);
json_string::const_iterator e = end(); json_string::const_iterator e = std_end();
for(json_string::const_iterator b = begin() + pos; b != e; + for(json_string::const_iterator b = std_begin() + pos; b !=
+b){ e; ++b){
if (*b == ch) return b - begin(); if (*b == ch) return b - std_begin();
} }
return json_string::npos; return json_string::npos;
} }
inline json_char & operator[] (size_t loc){ inline json_char & operator[] (size_t loc){
return _str -> mystring[loc + offset]; return _str -> mystring[loc + offset];
} }
inline json_char operator[] (size_t loc) const { inline json_char operator[] (size_t loc) const {
return _str -> mystring[loc + offset]; return _str -> mystring[loc + offset];
} }
inline void clear(){ len = 0; } inline void clear(){ len = 0; }
inline size_t length() const { return len; } inline size_t length() const { return len; }
inline const json_char * c_str() const { return toString().c_str(); } inline const json_char * c_str() const { return toString().c_str(); }
inline const json_char * data() const { return _str -> mystring.c_st r() + offset; } inline const json_char * data() const { return _str -> mystring.data () + offset; }
inline bool operator != (const json_shared_string & other) const { inline bool operator != (const json_shared_string & other) const {
if ((other._str == _str) && (other.len == len) && (other.off set == offset)) return false; if ((other._str == _str) && (other.len == len) && (other.off set == offset)) return false;
return other.toString() != toString(); return other.toString() != toString();
} }
inline bool operator == (const json_shared_string & other) const { inline bool operator == (const json_shared_string & other) const {
if ((other._str == _str) && (other.len == len) && (other.off set == offset)) return true; if ((other._str == _str) && (other.len == len) && (other.off set == offset)) return true;
return other.toString() == toString(); return other.toString() == toString();
} }
inline bool operator == (const json_string & other) const { inline bool operator == (const json_string & other) const {
return other == toString(); return other == toString();
} }
json_string & toString(void) const { json_string & toString(void) const {
//gonna have to do a real substring now anyway, so do it com pletely //gonna have to do a real substring now anyway, so do it com pletely
if (_str -> refCount == 1){ if (_str -> refCount == 1){
if (offset || len != _str -> mystring.length()){ if (offset || len != _str -> mystring.length()){
_str -> mystring = json_string(begin(), end( )); _str -> mystring = json_string(std_begin(), std_end());
} }
} else if (offset || len != _str -> mystring.length()){ } else if (offset || len != _str -> mystring.length()){
--_str -> refCount; //dont use deref because I know its not going to be deleted --_str -> refCount; //dont use deref because I know its not going to be deleted
_str = new json_shared_string_internal(json_string(b egin(), end())); _str = new(json_malloc<json_shared_string_internal>( 1)) json_shared_string_internal(json_string(std_begin(), std_end()));
} }
offset = 0; offset = 0;
return _str -> mystring; return _str -> mystring;
} }
inline void assign(const json_shared_string & other, size_t _offset, size_t _len){ inline void assign(const json_shared_string & other, size_t _offset, size_t _len){
if (other._str != _str){ if (other._str != _str){
deref(); deref();
_str = other._str; _str = other._str;
} }
skipping to change at line 125 skipping to change at line 264
} }
json_shared_string(const json_shared_string & other) : _str(other._s tr), offset(other.offset), len(other.len){ json_shared_string(const json_shared_string & other) : _str(other._s tr), offset(other.offset), len(other.len){
++_str -> refCount; ++_str -> refCount;
} }
json_shared_string & operator =(const json_shared_string & other){ json_shared_string & operator =(const json_shared_string & other){
if (other._str != _str){ if (other._str != _str){
deref(); deref();
_str = other._str; _str = other._str;
++_str -> refCount;
} }
++_str -> refCount;
offset = other.offset; offset = other.offset;
len = other.len; len = other.len;
return *this; return *this;
} }
json_shared_string & operator += (const json_char c){
toString() += c;
++len;
return *this;
}
//when doing a plus equal of another string, see if it shares the st
ring and starts where this one left off, in which case just increase len
JSON_PRIVATE JSON_PRIVATE
struct json_shared_string_internal { struct json_shared_string_internal {
inline json_shared_string_internal(const json_string & _myst ring) : mystring(_mystring), refCount(1) {} inline json_shared_string_internal(const json_string & _myst ring) : mystring(_mystring), refCount(1) {}
json_string mystring; json_string mystring;
size_t refCount PACKED(20); size_t refCount PACKED(20);
}; };
inline void deref(void){ inline void deref(void){
if (--_str -> refCount == 0){ if (--_str -> refCount == 0){
delete _str; _str -> ~json_shared_string_internal();
libjson_free<json_shared_string_internal>(_str);
} }
} }
mutable json_shared_string_internal * _str; mutable json_shared_string_internal * _str;
mutable size_t offset PACKED(20); mutable size_t offset PACKED(20);
mutable size_t len PACKED(20); mutable size_t len PACKED(20);
}; };
#ifdef JSON_LESS_MEMORY #ifdef JSON_LESS_MEMORY
#ifdef __GNUC__ #ifdef __GNUC__
#pragma pack(pop) #pragma pack(pop)
 End of changes. 16 change blocks. 
17 lines changed or deleted 214 lines changed or added


 JSONWorker.h   JSONWorker.h 
#ifndef JSON_WORKER_H #ifndef JSON_WORKER_H
#define JSON_WORKER_H #define JSON_WORKER_H
#include "JSONNode.h" #include "JSONNode.h"
#include "JSONSharedString.h" #include "JSONSharedString.h"
class JSONWorker { class JSONWorker {
public: public:
static json_string RemoveWhiteSpaceAndComments(const json_string & valu e_t, bool escapeQuotes) json_nothrow json_read_priority; static json_string RemoveWhiteSpaceAndComments(const json_string & valu e_t, bool escapeQuotes) json_nothrow json_read_priority;
static json_char * RemoveWhiteSpaceAndCommentsC(const json_string & value_t, bool escapeQuotes) json_nothrow json_read_priority;
#ifdef JSON_READ_PRIORITY #ifdef JSON_READ_PRIORITY
static JSONNode parse(const json_string & json) json_throws(std:: invalid_argument) json_read_priority; static JSONNode parse(const json_string & json) json_throws(std:: invalid_argument) json_read_priority;
static JSONNode parse_unformatted(const json_string & json) json_ throws(std::invalid_argument) json_read_priority; static JSONNode parse_unformatted(const json_string & json) json_ throws(std::invalid_argument) json_read_priority;
#if defined JSON_DEBUG || defined JSON_SAFE static JSONNode _parse_unformatted(const json_char * json, c
static JSONNode _parse_unformatted(const json_char * json, onst json_char * const end) json_throws(std::invalid_argument) json_read_pr
json_char & lastchar) json_throws(std::invalid_argument) json_read_priorit iority;
y;
#else
static JSONNode _parse_unformatted(const json_char * json)
json_throws(std::invalid_argument) json_read_priority;
#endif
#if defined JSON_DEBUG || defined JSON_SAFE static json_char * RemoveWhiteSpace(const json_string & valu
static json_char * RemoveWhiteSpace(const json_string & va e_t, size_t & len, bool escapeQuotes) json_nothrow json_read_priority;
lue_t, json_char & last, bool escapeQuotes) json_nothrow json_read_priority
;
#else
static json_char * RemoveWhiteSpace(const json_string & va
lue_t, bool escapeQuotes) json_nothrow json_read_priority;
#endif
static void DoArray(const internalJSONNode * parent, const json_s tring & value_t) json_nothrow json_read_priority; static void DoArray(const internalJSONNode * parent, const json_s tring & value_t) json_nothrow json_read_priority;
static void DoNode(const internalJSONNode * parent, const json_st ring & value_t) json_nothrow json_read_priority; static void DoNode(const internalJSONNode * parent, const json_st ring & value_t) json_nothrow json_read_priority;
#ifdef JSON_LESS_MEMORY #ifdef JSON_LESS_MEMORY
#define NAME_ENCODED this, true #define NAME_ENCODED this, true
#define STRING_ENCODED this, false #define STRING_ENCODED this, false
static json_string FixString(const json_string & value_t, const internalJSONNode * flag, bool which) json_nothrow json_read_priority; static json_string FixString(const json_string & value_t, const internalJSONNode * flag, bool which) json_nothrow json_read_priority;
#else #else
#define NAME_ENCODED _name_encoded #define NAME_ENCODED _name_encoded
skipping to change at line 53 skipping to change at line 46
template<json_char ch> template<json_char ch>
static size_t FindNextRelevant(const json_string & v alue_t, const size_t pos) json_nothrow json_read_priority; static size_t FindNextRelevant(const json_string & v alue_t, const size_t pos) json_nothrow json_read_priority;
#else #else
static size_t FindNextRelevant(json_char ch, const j son_string & value_t, const size_t pos) json_nothrow json_read_priority; static size_t FindNextRelevant(json_char ch, const j son_string & value_t, const size_t pos) json_nothrow json_read_priority;
#endif #endif
#endif #endif
static void UnfixString(const json_string & value_t, bool flag, json_st ring & res) json_nothrow; static void UnfixString(const json_string & value_t, bool flag, json_st ring & res) json_nothrow;
JSON_PRIVATE JSON_PRIVATE
#ifdef JSON_READ_PRIORITY #ifdef JSON_READ_PRIORITY
static json_char Hex(const json_char * & pos) json_nothrow; static json_char Hex(const json_char * & pos) json_nothrow;
static json_uchar UTF8(const json_char * & pos) json_nothrow; static json_uchar UTF8(const json_char * & pos, const json_char * const end) json_nothrow;
#endif #endif
#ifdef JSON_ESCAPE_WRITES #ifdef JSON_ESCAPE_WRITES
static json_string toUTF8(json_uchar p) json_nothrow; static json_string toUTF8(json_uchar p) json_nothrow;
#endif #endif
#ifdef JSON_UNICODE #ifdef JSON_UNICODE
static void UTF(const json_char * & pos, json_string & result) js on_nothrow; static void UTF(const json_char * & pos, json_string & result, co nst json_char * const end) json_nothrow;
#ifdef JSON_ESCAPE_WRITES #ifdef JSON_ESCAPE_WRITES
static json_string toSurrogatePair(json_uchar pos) json_no throw; static json_string toSurrogatePair(json_uchar pos) json_no throw;
#endif #endif
#endif #endif
#ifdef JSON_READ_PRIORITY #ifdef JSON_READ_PRIORITY
static void SpecialChar(const json_char * & pos, json_string & re s) json_nothrow; static void SpecialChar(const json_char * & pos, const json_char * const end, json_string & res) json_nothrow;
static void NewNode(const internalJSONNode * parent, const json_s tring & name, const json_string & value, bool array) json_nothrow; static void NewNode(const internalJSONNode * parent, const json_s tring & name, const json_string & value, bool array) json_nothrow;
#endif #endif
private:
JSONWorker(void);
}; };
#endif #endif
 End of changes. 7 change blocks. 
19 lines changed or deleted 11 lines changed or added


 JSON_Base64.h   JSON_Base64.h 
#ifndef JSON_BASE64_H #ifndef JSON_BASE64_H
#define JSON_BASE64_H #define JSON_BASE64_H
#include "JSONDebug.h" #include "JSONDebug.h"
#if defined(JSON_BINARY) || defined(JSON_EXPOSE_BASE64) //if this is not n eeded, don't waste space compiling it #if defined(JSON_BINARY) || defined(JSON_EXPOSE_BASE64) //if this is not n eeded, don't waste space compiling it
#include <string> #include "../Dependencies/libbase64++/libbase64++.h"
class JSONBase64 { class JSONBase64 {
public: public:
static json_string json_encode64(const unsigned char * binary, size_t b inline static json_string json_encode64(const unsigned char * binary, s
ytes) json_nothrow json_cold; ize_t bytes) json_nothrow json_cold;
static std::string json_decode64(const json_string & encoded) json_noth inline static std::string json_decode64(const json_string & encoded) js
row json_cold; on_nothrow json_cold;
private:
JSONBase64(void);
}; };
json_string JSONBase64::json_encode64(const unsigned char * binary, size_t
bytes) json_nothrow {
#if defined JSON_DEBUG || defined JSON_SAFE
return libbase64::encode<json_string, json_char, json_uchar, true>(
binary, bytes);
#else
return libbase64::encode<json_string, json_char, json_uchar, fal
se>(binary, bytes);
#endif
}
std::string JSONBase64::json_decode64(const json_string & encoded) json_not
hrow {
#if defined JSON_DEBUG || defined JSON_SAFE
return libbase64::decode<json_string, json_char, json_uchar, true>(
encoded);
#else
return libbase64::decode<json_string, json_char, json_uchar, false>(
encoded);
#endif
}
#endif #endif
#endif #endif
 End of changes. 3 change blocks. 
5 lines changed or deleted 29 lines changed or added


 NumberToString.h   NumberToString.h 
skipping to change at line 66 skipping to change at line 66
json_char num_str_result[getLenSize<sizeof(T)>::GETLEN]; json_char num_str_result[getLenSize<sizeof(T)>::GETLEN];
#endif #endif
num_str_result[getLenSize<sizeof(T)>::GETLEN - 1] = JSON_TEXT('\0 '); //null terminator num_str_result[getLenSize<sizeof(T)>::GETLEN - 1] = JSON_TEXT('\0 '); //null terminator
json_char * runner = &num_str_result[getLenSize<sizeof(T)>::GETLE N - 2]; json_char * runner = &num_str_result[getLenSize<sizeof(T)>::GETLE N - 2];
bool negative; bool negative;
START_MEM_SCOPE START_MEM_SCOPE
long value = (long)val; long value = (long)val;
//first thing, check if it's negative, if so, make it positive //first thing, check if it's negative, if so, make it positive
if (value < 0){ if (value < 0){
//HitScopeCoverage(_itoa_coverage);
value = -value; value = -value;
negative = true; negative = true;
} else { } else {
//HitScopeCoverage(_itoa_coverage);
negative = false; negative = false;
} }
//create the string //create the string
do { do {
//HitScopeCoverage(_itoa_coverage);
*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 END_MEM_SCOPE
//if it's negative, add the negation //if it's negative, add the negation
if (negative){ if (negative){
//HitScopeCoverage(_itoa_coverage);
*runner = JSON_TEXT('-'); *runner = JSON_TEXT('-');
return json_string(runner); return json_string(runner);
} else {
//HitScopeCoverage(_itoa_coverage);
} }
//HitScopeCoverage(_itoa_coverage);
return json_string(runner + 1); return json_string(runner + 1);
} }
#ifndef JSON_LIBRARY #ifndef JSON_LIBRARY
template<typename T> template<typename T>
static json_string _uitoa(T val) json_nothrow { static json_string _uitoa(T val) json_nothrow {
#ifdef JSON_LESS_MEMORY #ifdef JSON_LESS_MEMORY
json_auto<json_char> s(getLenSize<sizeof(T)>::GETLE N); json_auto<json_char> s(getLenSize<sizeof(T)>::GETLE N);
#else #else
json_char num_str_result[getLenSize<sizeof(T)>::GET LEN]; json_char num_str_result[getLenSize<sizeof(T)>::GET LEN];
skipping to change at line 130 skipping to change at line 123
#else #else
#define EXTRA_LONG long #define EXTRA_LONG long
#define FLOAT_STRING "%Lf" #define FLOAT_STRING "%Lf"
#define LFLOAT_STRING L"%Lf" #define LFLOAT_STRING L"%Lf"
#endif #endif
static json_string _ftoa(json_number value) json_nothrow { static json_string _ftoa(json_number value) json_nothrow {
#ifndef JSON_LIBRARY #ifndef JSON_LIBRARY
//ScopeCoverage(_ftoa_coverage, 6); //ScopeCoverage(_ftoa_coverage, 6);
if (json_unlikely(value >= 0.0 && _floatsAreEqual(value, ( json_number)((unsigned EXTRA_LONG long)value)))){ if (json_unlikely(value >= 0.0 && _floatsAreEqual(value, ( json_number)((unsigned EXTRA_LONG long)value)))){
//HitScopeCoverage(_ftoa_coverage);
return _uitoa<unsigned EXTRA_LONG long>((unsigned E XTRA_LONG long)value); return _uitoa<unsigned EXTRA_LONG long>((unsigned E XTRA_LONG long)value);
} else } else
#else #else
//ScopeCoverage(_ftoa_coverage, 5); //ScopeCoverage(_ftoa_coverage, 5);
#endif #endif
if (json_unlikely(_floatsAreEqual(value, (json_number)((lo ng EXTRA_LONG)value)))){ if (json_unlikely(_floatsAreEqual(value, (json_number)((lo ng EXTRA_LONG)value)))){
//HitScopeCoverage(_ftoa_coverage);
return _itoa<long EXTRA_LONG>((long EXTRA_LONG)valu e); return _itoa<long EXTRA_LONG>((long EXTRA_LONG)valu e);
} }
#ifdef JSON_LESS_MEMORY #ifdef JSON_LESS_MEMORY
json_auto<json_char> s(64); json_auto<json_char> s(64);
#else #else
json_char num_str_result[64]; json_char num_str_result[64];
#endif #endif
#ifdef JSON_UNICODE #ifdef JSON_UNICODE
std::swprintf(num_str_result, 63, LFLOAT_STRING, (EXTRA_LO NG double)value); std::swprintf(num_str_result, 63, LFLOAT_STRING, (EXTRA_LO NG double)value);
#else #else
//Thanks to Salvor Hardin for this Visual C++ fix //Thanks to Salvor Hardin for this Visual C++ fix
#ifdef _MSC_VER #ifdef _MSC_VER
_snprintf_s(num_str_result, 63, 63, FLOAT_STRING, ( EXTRA_LONG double)value); //yes, 63 appears twice using _snprintf_s() _snprintf_s(num_str_result, 63, 63, FLOAT_STRING, ( EXTRA_LONG double)value); //yes, 63 appears twice using _snprintf_s()
#else #else
std::snprintf(num_str_result, 63, FLOAT_STRING, (EX TRA_LONG double)value); std::snprintf(num_str_result, 63, FLOAT_STRING, (EX TRA_LONG double)value);
#endif #endif
#endif #endif
//strip the trailing zeros //strip the trailing zeros
for(json_char * pos = &num_str_result[0]; *pos; ++pos){ for(json_char * pos = &num_str_result[0]; *pos; ++pos){
//HitScopeCoverage(_ftoa_coverage);
if (json_unlikely(*pos == '.')){ //only care about after the decimal if (json_unlikely(*pos == '.')){ //only care about after the decimal
//HitScopeCoverage(_ftoa_coverage);
for(json_char * runner = pos + 1; *runner; ++runner ){ for(json_char * runner = pos + 1; *runner; ++runner ){
//HitScopeCoverage(_ftoa_coverage);
if (json_likely(*runner != JSON_TEXT('0'))) { if (json_likely(*runner != JSON_TEXT('0'))) {
//HitScopeCoverage(_ftoa_coverage);
pos = runner + 1; //have to go to the end 1.0001 pos = runner + 1; //have to go to the end 1.0001
} }
} }
*pos = JSON_TEXT('\0'); *pos = JSON_TEXT('\0');
break; break;
} }
} }
return json_string(num_str_result); return json_string(num_str_result);
} }
skipping to change at line 188 skipping to change at line 175
bool decimal = false; bool decimal = false;
bool scientific = false; bool scientific = false;
#ifdef JSON_STRICT #ifdef JSON_STRICT
bool leadingzero = false; bool leadingzero = false;
#endif #endif
//first letter is weird //first letter is weird
switch(*p){ switch(*p){
case JSON_TEXT('\0'): case JSON_TEXT('\0'):
HitScopeCoverage(isNumeric, emptystring);
return false; return false;
#ifndef JSON_STRICT #ifndef JSON_STRICT
case JSON_TEXT('.'): case JSON_TEXT('.'):
HitScopeCoverage(isNumeric, leadingperiod);
decimal = true; decimal = true;
break; break;
case JSON_TEXT('+'): case JSON_TEXT('+'):
#endif #endif
case JSON_TEXT('-'): case JSON_TEXT('-'):
switch (*(p + 1)){ switch (*(p + 1)){
case JSON_TEXT('.'): case JSON_TEXT('.'):
case JSON_TEXT('e'): case JSON_TEXT('e'):
case JSON_TEXT('E'): case JSON_TEXT('E'):
case JSON_TEXT('\0'): case JSON_TEXT('\0'):
HitScopeCoverage(isNumeric , minus_dot_e_null);
return false; return false;
case JSON_TEXT('0'): case JSON_TEXT('0'):
HitScopeCoverage(isNumeric , minus_zero);
#ifdef JSON_STRICT #ifdef JSON_STRICT
switch(*(p + 2)){ switch(*(p + 2)){
case JSON_TEXT('.' ): case JSON_TEXT('.' ):
case JSON_TEXT('e' ): case JSON_TEXT('e' ):
case JSON_TEXT('E' ): case JSON_TEXT('E' ):
HitScopeCo verage(isNumeric, minus_zero_dot_e);
leadingzer o = false; leadingzer o = false;
break; break;
case JSON_TEXT('\0 '): case JSON_TEXT('\0 '):
HitScopeCo verage(isNumeric, minus_zero_null);
return tru e; return tru e;
default: default:
HitScopeCo verage(isNumeric, minus_zero_default);
leadingzer o = true; leadingzer o = true;
break; break;
} }
#endif #endif
++p; ++p;
break; break;
default: default:
HitScopeCoverage(isNumeric , minus_default);
break; break;
} }
break; break;
case JSON_TEXT('1'): case JSON_TEXT('1'):
case JSON_TEXT('2'): case JSON_TEXT('2'):
case JSON_TEXT('3'): case JSON_TEXT('3'):
case JSON_TEXT('4'): case JSON_TEXT('4'):
case JSON_TEXT('5'): case JSON_TEXT('5'):
case JSON_TEXT('6'): case JSON_TEXT('6'):
case JSON_TEXT('7'): case JSON_TEXT('7'):
case JSON_TEXT('8'): case JSON_TEXT('8'):
case JSON_TEXT('9'): case JSON_TEXT('9'):
HitScopeCoverage(isNumeric, digit);
break; break;
case JSON_TEXT('0'): case JSON_TEXT('0'):
++p; ++p;
#ifdef JSON_STRICT #ifdef JSON_STRICT
leadingzero = true; leadingzero = true;
#endif #endif
HitScopeCoverage(isNumeric, zero);
switch(*p){ switch(*p){
case JSON_TEXT('.'): case JSON_TEXT('.'):
HitScopeCoverage(isNumeric, zero_ dot);
decimal = true; decimal = true;
break; break;
case JSON_TEXT('e'): case JSON_TEXT('e'):
case JSON_TEXT('E'): case JSON_TEXT('E'):
#ifdef JSON_STRICT #ifdef JSON_STRICT
leadingzero = false; //not l eading, just a zero leadingzero = false; //not l eading, just a zero
#endif #endif
HitScopeCoverage(isNumeric, zero_e);
scientific = true; scientific = true;
++p; ++p;
switch(*p){ switch(*p){
case JSON_TEXT('\0'): case JSON_TEXT('\0'):
HitScopeCoverage(is Numeric, zero_e_null);
return false; return false;
case JSON_TEXT('-'): case JSON_TEXT('-'):
case JSON_TEXT('+'): case JSON_TEXT('+'):
#ifndef JSON_STRICT #ifndef JSON_STRICT
case JSON_TEXT('0'): //ca nt have a leading zero in scrict case JSON_TEXT('0'): //ca nt have a leading zero in scrict
HitScopeCoverage( isNumeric, zero_e_zero);
#endif #endif
case JSON_TEXT('1'): case JSON_TEXT('1'):
case JSON_TEXT('2'): case JSON_TEXT('2'):
case JSON_TEXT('3'): case JSON_TEXT('3'):
case JSON_TEXT('4'): case JSON_TEXT('4'):
case JSON_TEXT('5'): case JSON_TEXT('5'):
case JSON_TEXT('6'): case JSON_TEXT('6'):
case JSON_TEXT('7'): case JSON_TEXT('7'):
case JSON_TEXT('8'): case JSON_TEXT('8'):
case JSON_TEXT('9'): case JSON_TEXT('9'):
HitScopeCoverage(is Numeric, zero_e_digit_sign);
break; break;
default: default:
HitScopeCoverage(is Numeric, zero_e_default);
return false; return false;
} }
break; break;
#ifndef JSON_STRICT #ifndef JSON_STRICT
case JSON_TEXT('x'): case JSON_TEXT('x'):
HitScopeCoverage(isNumeric , zero_x);
return (str.find_first_not _of(JSON_TEXT("0123456789ABCDEFabcdef"), 2) == json_string::npos); return (str.find_first_not _of(JSON_TEXT("0123456789ABCDEFabcdef"), 2) == json_string::npos);
case JSON_TEXT('1'): case JSON_TEXT('1'):
case JSON_TEXT('2'): case JSON_TEXT('2'):
case JSON_TEXT('3'): case JSON_TEXT('3'):
case JSON_TEXT('4'): case JSON_TEXT('4'):
case JSON_TEXT('5'): case JSON_TEXT('5'):
case JSON_TEXT('6'): case JSON_TEXT('6'):
case JSON_TEXT('7'): case JSON_TEXT('7'):
HitScopeCoverage(isNumeric , zero_octal);
return (str.find_first_not _of(JSON_TEXT("01234567"), 1) == json_string::npos); return (str.find_first_not _of(JSON_TEXT("01234567"), 1) == json_string::npos);
#endif #endif
case JSON_TEXT('\0'): //just 0 case JSON_TEXT('\0'): //just 0
HitScopeCoverage(isNumeric, zero_ null);
return true; return true;
default: default:
HitScopeCoverage(isNumeric, zero_ default);
return false; return false;
} }
HitScopeCoverage(isNumeric, zero_break);
break; break;
default: default:
HitScopeCoverage(isNumeric, default_first);
return false; return false;
} }
++p; ++p;
//next digits //next digits
while (*p){ while (*p){
switch(*p){ switch(*p){
case JSON_TEXT('.'): case JSON_TEXT('.'):
if (json_unlikely(decimal)){ if (json_unlikely(decimal)){
HitScopeCoverage(isNumeric, _dot_already);
return false; //multiple de cimals return false; //multiple de cimals
} }
HitScopeCoverage(isNumeric, _dot);
if (json_unlikely(scientific)){ if (json_unlikely(scientific)){
HitScopeCoverage(isNumeric, _dot_scientific);
return false; return false;
} }
HitScopeCoverage(isNumeric, _dot_no tscientific);
decimal = true; decimal = true;
break; break;
case JSON_TEXT('e'): case JSON_TEXT('e'):
case JSON_TEXT('E'): case JSON_TEXT('E'):
if (json_unlikely(scientific)){ if (json_unlikely(scientific)){
//TODO Not hit in unit test
s
HitScopeCoverage(isNumeric,
_e_scientific);
return false; return false;
} }
HitScopeCoverage(isNumeric, _e_notsc ientific);
scientific = true; scientific = true;
++p; ++p;
switch(*p){ switch(*p){
case JSON_TEXT('\0'): case JSON_TEXT('\0'):
//TODO Not hit in un
it tests
HitScopeCoverage(isNumeric
, _e_null);
return false; return false;
case JSON_TEXT('-'): case JSON_TEXT('-'):
case JSON_TEXT('+'): case JSON_TEXT('+'):
if (!isdigit(*(p + 1 ))){ if (!isdigit(*(p + 1 ))){
//TODO Not h
it in unit tests
HitScopeCove
rage(isNumeric, _e_sign_notdigit);
return false ; return false ;
} }
#ifdef JSON_STRICT #ifdef JSON_STRICT
if (*(p + 1) == JSON_TEXT('0')){ //no leading zeros on scientific notations if (*(p + 1) == JSON_TEXT('0')){ //no leading zeros on scientific notations
HitS copeCoverage(isNumeric, _e_sign_zero);
retu rn false; retu rn false;
} }
#endif #endif
HitScopeCoverage(isN umeric, _e_sign);
break; break;
#ifndef JSON_STRICT #ifndef JSON_STRICT
case JSON_TEXT('0'): //cant have a leading zero in scrict case JSON_TEXT('0'): //cant have a leading zero in scrict
#endif #endif
case JSON_TEXT('1'): case JSON_TEXT('1'):
case JSON_TEXT('2'): case JSON_TEXT('2'):
case JSON_TEXT('3'): case JSON_TEXT('3'):
case JSON_TEXT('4'): case JSON_TEXT('4'):
case JSON_TEXT('5'): case JSON_TEXT('5'):
case JSON_TEXT('6'): case JSON_TEXT('6'):
case JSON_TEXT('7'): case JSON_TEXT('7'):
case JSON_TEXT('8'): case JSON_TEXT('8'):
case JSON_TEXT('9'): case JSON_TEXT('9'):
HitScopeCoverage(isNumeric , _e_digit);
break; break;
default: default:
//TODO Not hit in un
it tests
HitScopeCoverage(isNumeric
, _e_default);
return false; return false;
} }
HitScopeCoverage(isNumeric, _e_break );
break; break;
case JSON_TEXT('0'): case JSON_TEXT('0'):
case JSON_TEXT('1'): case JSON_TEXT('1'):
case JSON_TEXT('2'): case JSON_TEXT('2'):
case JSON_TEXT('3'): case JSON_TEXT('3'):
case JSON_TEXT('4'): case JSON_TEXT('4'):
case JSON_TEXT('5'): case JSON_TEXT('5'):
case JSON_TEXT('6'): case JSON_TEXT('6'):
case JSON_TEXT('7'): case JSON_TEXT('7'):
case JSON_TEXT('8'): case JSON_TEXT('8'):
case JSON_TEXT('9'): case JSON_TEXT('9'):
HitScopeCoverage(isNumeric, _digit);
break; break;
default: default:
HitScopeCoverage(isNumeric, _default );
return false; return false;
} }
++p; ++p;
} }
#ifdef JSON_STRICT #ifdef JSON_STRICT
if (leadingzero && !decimal){ if (leadingzero && !decimal){
HitScopeCoverage(isNumeric, leadingzero_and_nodec imal);
return false; return false;
} }
#endif #endif
HitScopeCoverage(isNumeric, returntrue);
return true; return true;
} }
#endif #endif
#ifdef JSON_STRICT #ifdef JSON_STRICT
//much faster because no octal or hex support //much faster because no octal or hex support
static json_number _atof (const json_char * num){ static json_number _atof (const json_char * num){
json_number sign = (json_number)1.0; json_number sign = (json_number)1.0;
//sign //sign
if (*num==JSON_TEXT('-')){ if (*num==JSON_TEXT('-')){
HitScopeCoverage(_atof, negative);
sign = -1.0; sign = -1.0;
++num; ++num;
} else { } else {
HitScopeCoverage(_atof, otnegative);
} }
//skip leading zero if one //skip leading zero if one
#if defined(JSON_SAFE) || defined(JSON_DEBUG) #if defined(JSON_SAFE) || defined(JSON_DEBUG)
bool _leadingzeros = *num == JSON_TEXT('0'); bool _leadingzeros = *num == JSON_TEXT('0');
bool _leadingdigits = false; bool _leadingdigits = false;
#endif #endif
if (*num == JSON_TEXT('0')){ if (*num == JSON_TEXT('0')){
HitScopeCoverage(_atof, leadingzero);
++num; ++num;
} }
#ifdef JSON_STRICT #ifdef JSON_STRICT
else if (json_likely(*num < JSON_TEXT('1') || *num > JSON_TEXT('9'))){ else if (json_likely(*num < JSON_TEXT('1') || *num > JSON_TEXT('9'))){
return std::numeric_limits<json_number>::sig naling_NaN(); return std::numeric_limits<json_number>::sig naling_NaN();
} }
#endif #endif
JSON_ASSERT_SAFE(*num != JSON_TEXT('0'), JSON_TEXT("multi ple leading zeros"), return std::numeric_limits<json_number>::signaling_NaN (); ); JSON_ASSERT_SAFE(*num != JSON_TEXT('0'), JSON_TEXT("multi ple leading zeros"), return std::numeric_limits<json_number>::signaling_NaN (); );
// Number // Number
json_number n = (json_number)0.0; json_number n = (json_number)0.0;
if (json_likely(*num >= JSON_TEXT('1') && *num <= JSON_TEX T('9'))){ if (json_likely(*num >= JSON_TEXT('1') && *num <= JSON_TEX T('9'))){
#if defined(JSON_SAFE) || defined(JSON_DEBUG) #if defined(JSON_SAFE) || defined(JSON_DEBUG)
_leadingdigits = true; _leadingdigits = true;
#endif #endif
HitScopeCoverage(_atof, digits);
do { do {
n = (n * 10.0) + (*num++ - JSON_TEXT('0')); n = (n * 10.0) + (*num++ - JSON_TEXT('0'));
} while (*num >= JSON_TEXT('0') && *num <= JSON_TEX T('9')); } while (*num >= JSON_TEXT('0') && *num <= JSON_TEX T('9'));
} else { } else {
JSON_ASSERT_SAFE( JSON_ASSERT_SAFE(
(*num) == JSON_TE XT('.') || //.xxx (*num) == JSON_TE XT('.') || //.xxx
(*num) == JSON_TE XT('e') || //0Exxx (*num) == JSON_TE XT('e') || //0Exxx
(*num) == JSON_TE XT('E') || //0exxx (*num) == JSON_TE XT('E') || //0exxx
(*num) == JSON_TE XT('\0') //end of the number, just zero (*num) == JSON_TE XT('\0') //end of the number, just zero
, JSON_TEXT("firs t digit not a number, e, period, or terminator"), return std::numeric_limit s<json_number>::signaling_NaN(); ); , JSON_TEXT("firs t digit not a number, e, period, or terminator"), return std::numeric_limit s<json_number>::signaling_NaN(); );
HitScopeCoverage(_atof, notdigits);
} }
// Fractional part // Fractional part
json_number scale = (json_number)0.0; json_number scale = (json_number)0.0;
if (*num == JSON_TEXT('.')) { if (*num == JSON_TEXT('.')) {
JSON_ASSERT_SAFE(_leadingzeros || _leadingdigits, JSON_TEXT("period without leading anything"), return std::numeric_limits<js on_number>::signaling_NaN(); ); JSON_ASSERT_SAFE(_leadingzeros || _leadingdigits, JSON_TEXT("period without leading anything"), return std::numeric_limits<js on_number>::signaling_NaN(); );
HitScopeCoverage(_atof, decimal);
++num; ++num;
for(; *num >= JSON_TEXT('0') && *num <= JSON_TEXT( '9');){ for(; *num >= JSON_TEXT('0') && *num <= JSON_TEXT( '9');){
HitScopeCoverage(_atof, decimalloop);
n = (n * 10.0) + (*num++ - JSON_TEXT('0')); n = (n * 10.0) + (*num++ - JSON_TEXT('0'));
--scale; --scale;
}; };
} else { } else {
JSON_ASSERT_SAFE(!_leadingzeros || n == 0, JSON_TE XT("leading zero on an int"), return std::numeric_limits<json_number>::sign aling_NaN(); ); JSON_ASSERT_SAFE(!_leadingzeros || n == 0, JSON_TE XT("leading zero on an int"), return std::numeric_limits<json_number>::sign aling_NaN(); );
JSON_ASSERT_SAFE( JSON_ASSERT_SAFE(
(*num) == JSON_TE XT('e') || //0Exxx (*num) == JSON_TE XT('e') || //0Exxx
(*num) == JSON_TE XT('E') || //0exxx (*num) == JSON_TE XT('E') || //0exxx
(*num) == JSON_TE XT('\0') //end of the number, just zero (*num) == JSON_TE XT('\0') //end of the number, just zero
, JSON_TEXT("next char not an e or terminator"), return std::numeric_limits<json_number>::si gnaling_NaN(); ); , JSON_TEXT("next char not an e or terminator"), return std::numeric_limits<json_number>::si gnaling_NaN(); );
HitScopeCoverage(_atof, nodecimal);
} }
// Exponent // Exponent
int subscale = 0, signsubscale = 1; int subscale = 0, signsubscale = 1;
if (json_unlikely(*num == JSON_TEXT('e') || *num == JSON_T EXT('E'))){ if (json_unlikely(*num == JSON_TEXT('e') || *num == JSON_T EXT('E'))){
HitScopeCoverage(_atof, exponent);
++num; ++num;
switch(*num){ switch(*num){
case JSON_TEXT('+'): case JSON_TEXT('+'):
HitScopeCoverage(_atof, positiveexp onent);
++num; ++num;
break; break;
case JSON_TEXT('-'): case JSON_TEXT('-'):
HitScopeCoverage(_atof, negativeexp onent);
signsubscale = -1; signsubscale = -1;
++num; ++num;
JSON_ASSERT_SAFE(*num != JSON_TEXT( '0'), JSON_TEXT("negative cant be followed by leading zero even after E"), return std::numeric_limits<json_number>::signaling_NaN(); ); JSON_ASSERT_SAFE(*num != JSON_TEXT( '0'), JSON_TEXT("negative cant be followed by leading zero even after E"), return std::numeric_limits<json_number>::signaling_NaN(); );
break; break;
default: default:
HitScopeCoverage(_atof, nosignexpon ent);
break; break;
} }
JSON_ASSERT_SAFE(*num != JSON_TEXT('\0'), JSON_TEXT ("no exponent for scientific notation"), return std::numeric_limits<json_nu mber>::signaling_NaN(); ); JSON_ASSERT_SAFE(*num != JSON_TEXT('\0'), JSON_TEXT ("no exponent for scientific notation"), return std::numeric_limits<json_nu mber>::signaling_NaN(); );
while (*num >= JSON_TEXT('0') && *num <= JSON_TEXT( '9')){ while (*num >= JSON_TEXT('0') && *num <= JSON_TEXT( '9')){
HitScopeCoverage(_atof, afterexponent);
subscale=(subscale * 10) + (*num++ - JSON_TE XT('0')); subscale=(subscale * 10) + (*num++ - JSON_TE XT('0'));
} }
} else {
HitScopeCoverage(_atof, noexponent);
} }
JSON_ASSERT_SAFE(*num == JSON_TEXT('\0'), JSON_TEXT("done with number, not at terminator"), return std::numeric_limits<json_number>:: signaling_NaN(); ); JSON_ASSERT_SAFE(*num == JSON_TEXT('\0'), JSON_TEXT("done with number, not at terminator"), return std::numeric_limits<json_number>:: signaling_NaN(); );
return sign * n * pow((json_number)10.0, scale + subscale * signsubscale); // number = +/- number.fraction * 10^+/- exponent return sign * n * pow((json_number)10.0, scale + subscale * signsubscale); // number = +/- number.fraction * 10^+/- exponent
} }
#endif #endif
}; };
#endif #endif
 End of changes. 65 change blocks. 
87 lines changed or deleted 0 lines changed or added


 internalJSONNode.h   internalJSONNode.h 
skipping to change at line 202 skipping to change at line 202
#ifdef JSON_MUTEX_CALLBACKS #ifdef JSON_MUTEX_CALLBACKS
void _set_mutex(void * mutex, bool unset = true) json_nothrow jso n_cold; void _set_mutex(void * mutex, bool unset = true) json_nothrow jso n_cold;
void _unset_mutex(void) json_nothrow json_cold; void _unset_mutex(void) json_nothrow json_cold;
#endif #endif
#ifdef JSON_UNIT_TEST #ifdef JSON_UNIT_TEST
static void incinternalAllocCount(void) json_nothrow; static void incinternalAllocCount(void) json_nothrow;
static void decinternalAllocCount(void) json_nothrow; static void decinternalAllocCount(void) json_nothrow;
#endif #endif
#ifdef JSON_WRITE_PRIORITY #ifdef JSON_WRITE_PRIORITY
void DumpRawString(json_string & output) const json_nothrow json_write_priority;
void WriteName(bool formatted, bool arrayChild, json_string & out put) const json_nothrow json_write_priority; void WriteName(bool formatted, bool arrayChild, json_string & out put) const json_nothrow json_write_priority;
#ifdef JSON_ARRAY_SIZE_ON_ONE_LINE #ifdef JSON_ARRAY_SIZE_ON_ONE_LINE
void WriteChildrenOneLine(unsigned int indent, json_string & output) const json_nothrow json_write_priority; void WriteChildrenOneLine(unsigned int indent, json_string & output) const json_nothrow json_write_priority;
#endif #endif
void WriteChildren(unsigned int indent, json_string & output) con st json_nothrow json_write_priority; void WriteChildren(unsigned int indent, json_string & output) con st json_nothrow json_write_priority;
void WriteComment(unsigned int indent, json_string & output) cons t json_nothrow json_write_priority; void WriteComment(unsigned int indent, json_string & output) cons t json_nothrow json_write_priority;
void Write(unsigned int indent, bool arrayChild, json_string & ou tput) const json_nothrow json_write_priority; void Write(unsigned int indent, bool arrayChild, json_string & ou tput) const json_nothrow json_write_priority;
#endif #endif
inline bool isContainer(void) const json_nothrow { inline bool isContainer(void) const json_nothrow {
 End of changes. 1 change blocks. 
0 lines changed or deleted 1 lines changed or added


 libjson.h   libjson.h 
skipping to change at line 243 skipping to change at line 243
#else #else
return str; return str;
#endif #endif
} }
#endif #endif
#ifdef JSON_READ_PRIORITY #ifdef JSON_READ_PRIORITY
//if json is invalid, it throws a std::invalid_argument ex ception //if json is invalid, it throws a std::invalid_argument ex ception
inline static JSONNode parse(const json_string & json) jso n_throws(std::invalid_argument) { inline static JSONNode parse(const json_string & json) jso n_throws(std::invalid_argument) {
#ifdef JSON_PREPARSE #ifdef JSON_PREPARSE
#if defined JSON_DEBUG || defined JSON_SAFE size_t len;
json_char temp; json_auto<json_char> buffer(JSONWorker::Remo
json_auto<json_char> buffer(JSONWork veWhiteSpace(json, len, false));
er::RemoveWhiteSpace(json, temp, false));
#else
json_auto<json_char> buffer(JSONWork
er::RemoveWhiteSpace(json, false));
#endif
return JSONPreparse::isValidRoot(buffer.ptr) ; return JSONPreparse::isValidRoot(buffer.ptr) ;
#else #else
return JSONWorker::parse(json); return JSONWorker::parse(json);
#endif #endif
} }
inline static JSONNode parse_unformatted(const json_string & json) json_throws(std::invalid_argument) { inline static JSONNode parse_unformatted(const json_string & json) json_throws(std::invalid_argument) {
#ifdef JSON_PREPARSE #ifdef JSON_PREPARSE
return JSONPreparse::isValidRoot(json); return JSONPreparse::isValidRoot(json);
#else #else
skipping to change at line 271 skipping to change at line 267
} }
#ifdef JSON_VALIDATE #ifdef JSON_VALIDATE
inline static bool is_valid(const json_string & jso n) json_nothrow { inline static bool is_valid(const json_string & jso n) json_nothrow {
#ifdef JSON_SECURITY_MAX_STRING_LENGTH #ifdef JSON_SECURITY_MAX_STRING_LENGTH
if (json_unlikely(json.length() > JSON_S ECURITY_MAX_STRING_LENGTH)){ if (json_unlikely(json.length() > JSON_S ECURITY_MAX_STRING_LENGTH)){
JSON_FAIL(JSON_TEXT("Exceeding JS ON_SECURITY_MAX_STRING_LENGTH")); JSON_FAIL(JSON_TEXT("Exceeding JS ON_SECURITY_MAX_STRING_LENGTH"));
return false; return false;
} }
#endif #endif
return JSONValidator::isValidRoot(JSONWorker json_auto<json_char> s;
::RemoveWhiteSpaceAndComments(json, false).c_str()); s.set(JSONWorker::RemoveWhiteSpaceAndComment
sC(json, false));
return JSONValidator::isValidRoot(s.ptr);
} }
inline static bool is_valid_unformatted(const json_ string & json) json_nothrow { inline static bool is_valid_unformatted(const json_ string & json) json_nothrow {
#ifdef JSON_SECURITY_MAX_STRING_LENGTH #ifdef JSON_SECURITY_MAX_STRING_LENGTH
if (json_unlikely(json.length() > JSON_S ECURITY_MAX_STRING_LENGTH)){ if (json_unlikely(json.length() > JSON_S ECURITY_MAX_STRING_LENGTH)){
JSON_FAIL(JSON_TEXT("Exceeding JS ON_SECURITY_MAX_STRING_LENGTH")); JSON_FAIL(JSON_TEXT("Exceeding JS ON_SECURITY_MAX_STRING_LENGTH"));
return false; return false;
} }
#endif #endif
return JSONValidator::isValidRoot(json.c_str ()); return JSONValidator::isValidRoot(json.c_str ());
 End of changes. 2 change blocks. 
10 lines changed or deleted 7 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/