| 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 | |
|
| 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 | |
|
| 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 | |
|
| 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 | |
|