JSONOptions.h | JSONOptions.h | |||
---|---|---|---|---|
skipping to change at line 37 | skipping to change at line 37 | |||
* from the errors that it encounters. This option is recommended for tho se who | * from the errors that it encounters. This option is recommended for tho se who | |||
* feel it's possible for their program to encounter invalid json. | * feel it's possible for their program to encounter invalid json. | |||
*/ | */ | |||
#define JSON_SAFE | #define JSON_SAFE | |||
/* | /* | |||
* JSON_STDERROR routes error messages to cerr instead of a callback, this | * JSON_STDERROR routes error messages to cerr instead of a callback, this | |||
* option hides the callback registering function. This will usually disp lay | * option hides the callback registering function. This will usually disp lay | |||
* messages in the console | * messages in the console | |||
*/ | */ | |||
//#define JSON_STDERROR | #define JSON_STDERROR | |||
/* | /* | |||
* JSON_PREPARSE causes all parsing to be done immediately. By default, l ibjson | * JSON_PREPARSE causes all parsing to be done immediately. By default, l ibjson | |||
* parses nodes on the fly as they are needed, this makes parsing much fas ter if | * parses nodes on the fly as they are needed, this makes parsing much fas ter if | |||
* your program gets a lot of information that it doesn't need. An exampl e of | * your program gets a lot of information that it doesn't need. An exampl e of | |||
* this would be a client application communicating with a server if the s erver | * this would be a client application communicating with a server if the s erver | |||
* returns things like last modified date and other things that you don't use. | * returns things like last modified date and other things that you don't use. | |||
*/ | */ | |||
//#define JSON_PREPARSE | //#define JSON_PREPARSE | |||
skipping to change at line 140 | skipping to change at line 140 | |||
* will use whatever it's defined as for the newline signifier, otherwise, it will use | * will use whatever it's defined as for the newline signifier, otherwise, it will use | |||
* standard unix \n. | * standard unix \n. | |||
*/ | */ | |||
//#define JSON_NEWLINE "\r\n" //\r\n is standard for most windows and dos programs | //#define JSON_NEWLINE "\r\n" //\r\n is standard for most windows and dos programs | |||
/* | /* | |||
* JSON_COMMENTS tells libjson to store and write comments. libjson alway s supports | * JSON_COMMENTS tells libjson to store and write comments. libjson alway s supports | |||
* parsing json that has comments in it as it simply ignores them, but wit h this option | * parsing json that has comments in it as it simply ignores them, but wit h this option | |||
* it keeps the comments and allows you to insert further comments | * it keeps the comments and allows you to insert further comments | |||
*/ | */ | |||
//#define JSON_COMMENTS | #define JSON_COMMENTS | |||
/* | /* | |||
* JSON_INDENT affects how libjson writes. If this option is turned on, l ibjson | * JSON_INDENT affects how libjson writes. If this option is turned on, l ibjson | |||
* will use \t to indent formatted json, otherwise it will use the number of characters | * will use \t to indent formatted json, otherwise it will use the number of characters | |||
* that you specify. If this is not turned on, then it will use the tab ( \t) character | * that you specify. If this is not turned on, then it will use the tab ( \t) character | |||
*/ | */ | |||
//#define JSON_INDENT " " | //#define JSON_INDENT " " | |||
/* | /* | |||
* JSON_WRITE_BASH_COMMENTS will cause libjson to write all comments in ba sh (#) style | * JSON_WRITE_BASH_COMMENTS will cause libjson to write all comments in ba sh (#) style | |||
skipping to change at line 166 | skipping to change at line 166 | |||
/* | /* | |||
* JSON_WRITE_SINGLE_LINE_COMMENTS will cause libjson to write all comment s in using // | * JSON_WRITE_SINGLE_LINE_COMMENTS will cause libjson to write all comment s in using // | |||
* notation, or (#) if that option is on. Some parsers do not support mul tiline C comments | * notation, or (#) if that option is on. Some parsers do not support mul tiline C comments | |||
* although, this option is not needed for bash comments, as they are all single line anyway | * although, this option is not needed for bash comments, as they are all single line anyway | |||
*/ | */ | |||
//#define JSON_WRITE_SINGLE_LINE_COMMENTS | //#define JSON_WRITE_SINGLE_LINE_COMMENTS | |||
/* | /* | |||
* JSON_VALIDATE turns on validation features of libjson. This option req uires JSON_SAFE | * JSON_VALIDATE turns on validation features of libjson. This option req uires JSON_SAFE | |||
*/ | */ | |||
//#define JSON_VALIDATE | #define JSON_VALIDATE | |||
/* | /* | |||
* JSON_CASE_INSENSITIVE_FUNCTIONS turns on funtions for finding child nod es in a case- | * JSON_CASE_INSENSITIVE_FUNCTIONS turns on funtions for finding child nod es in a case- | |||
* insenititve way | * insenititve way | |||
*/ | */ | |||
//#define JSON_CASE_INSENSITIVE_FUNCTIONS | #define JSON_CASE_INSENSITIVE_FUNCTIONS | |||
/* | /* | |||
* JSON_UNIT_TEST is used to maintain and debug the libjson. It makes all private | * 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. | |||
*/ | */ | |||
//#define JSON_UNIT_TEST | //#define JSON_UNIT_TEST | |||
/* | /* | |||
* JSON_INDEX_TYPE allows you th change the size type for the children fun ctions. If this | * JSON_INDEX_TYPE allows you th change the size type for the children fun ctions. If this | |||
End of changes. 4 change blocks. | ||||
4 lines changed or deleted | 4 lines changed or added | |||
NumberToString.h | NumberToString.h | |||
---|---|---|---|---|
#ifndef NUMBERTOSTRING_H | #ifndef NUMBERTOSTRING_H | |||
#define NUMBERTOSTRING_H | #define NUMBERTOSTRING_H | |||
#include "JSONDebug.h" | #include "JSONDebug.h" | |||
#include "JSONMemory.h" | #include "JSONMemory.h" | |||
#include <cstdio> | #include <cstdio> | |||
static unsigned int getlen(unsigned int size){ | template <unsigned int GETLENSIZE> | |||
switch (size){ | struct getLenSize | |||
case 1: | { | |||
return 5; //3 digits for the number, plus null terminato | char tmp[GETLENSIZE == 16]; // compile time assertion | |||
r and negation | enum {GETLEN = 41}; | |||
case 2: | }; | |||
return 7; //5 digits for the number, plus null terminato | ||||
r and negation | template<> | |||
case 4: | struct getLenSize<1> | |||
return 12; //10 digits for the number, plus null terminat | { | |||
or and negation | enum {GETLEN = 5}; | |||
case 8: | }; | |||
return 22; //20 digits for the number, plus null terminat | ||||
or and negation | template <> | |||
} | struct getLenSize<2> | |||
JSON_ASSERT(size == 16, JSON_TEXT("template is not recognized 2^x in si | { | |||
ze")); | enum {GETLEN = 7}; | |||
return 41; //39 digits for the number, plus null terminator and negati | }; | |||
on | ||||
} | template <> | |||
struct getLenSize<4> | ||||
{ | ||||
enum {GETLEN = 12}; | ||||
}; | ||||
template <> | ||||
struct getLenSize<8> | ||||
{ | ||||
enum {GETLEN = 22}; | ||||
}; | ||||
class NumberToString { | class NumberToString { | |||
public: | public: | |||
template<typename T> | template<typename T> | |||
static json_string _itoa(T val, unsigned int size){ | static json_string _itoa(T val){ | |||
long value = (long)val; | long value = (long)val; | |||
const unsigned int digits = getlen(size); | json_char result[getLenSize<sizeof(T)>::GETLEN]; | |||
json_auto<json_char> result(digits); | result[getLenSize<sizeof(T)>::GETLEN - 1] = JSON_TEXT('\0'); //nu | |||
result.ptr[digits - 1] = JSON_TEXT('\0'); //null terminator | ll terminator | |||
json_char * runner = &result.ptr[digits - 2]; | json_char * runner = &result[getLenSize<sizeof(T)>::GETLEN - 2]; | |||
bool negative; | bool negative; | |||
//first thing, check if it's negative, if so, make it positive | //first thing, check if it's negative, if so, make it positive | |||
if (value < 0){ | if (value < 0){ | |||
value = -value; | value = -value; | |||
negative = true; | negative = true; | |||
} else { | } else { | |||
negative = false; | negative = false; | |||
} | } | |||
skipping to change at line 60 | skipping to change at line 75 | |||
*runner = JSON_TEXT('-'); | *runner = JSON_TEXT('-'); | |||
res = runner; | res = runner; | |||
} else { | } else { | |||
res = runner + 1; | res = runner + 1; | |||
} | } | |||
return res; | return res; | |||
} | } | |||
#ifndef JSON_LIBRARY | #ifndef JSON_LIBRARY | |||
template<typename T> | template<typename T> | |||
static json_string _uitoa(T val, unsigned int size){ | static json_string _uitoa(T val){ | |||
unsigned long value = val; | unsigned long value = (unsigned long)val; | |||
const unsigned int digits = getlen(size) - 1; //minus one | json_char result[getLenSize<sizeof(T)>::GETLEN]; | |||
because no '-' char | result[getLenSize<sizeof(T)>::GETLEN - 1] = JSON_TEXT('\0' | |||
json_auto<json_char> result(digits); | ); //null terminator | |||
result.ptr[digits - 1] = JSON_TEXT('\0'); //null terminato | json_char * runner = &result[getLenSize<sizeof(T)>::GETLEN | |||
r | - 2]; | |||
json_char * runner = &result.ptr[digits - 2]; | ||||
//create the string | //create the string | |||
do { | do { | |||
*runner-- = (json_char)(value % 10) + JSON_TEXT('0' ); | *runner-- = (json_char)(value % 10) + JSON_TEXT('0' ); | |||
} while(value /= 10); | } while(value /= 10); | |||
json_string res = runner + 1; | json_string res = runner + 1; | |||
return res; | return res; | |||
} | } | |||
#endif | #endif | |||
skipping to change at line 89 | skipping to change at line 103 | |||
json_char result[64]; | json_char result[64]; | |||
#ifdef JSON_UNICODE | #ifdef JSON_UNICODE | |||
swprintf(result, 63, L"%f", value); | swprintf(result, 63, L"%f", value); | |||
#else | #else | |||
snprintf(result, 63, "%f", value); | snprintf(result, 63, "%f", value); | |||
#endif | #endif | |||
//strip the trailing zeros | //strip the trailing zeros | |||
for(json_char * pos = &result[0]; *pos; ++pos){ | for(json_char * pos = &result[0]; *pos; ++pos){ | |||
if (*pos == '.'){ //only care about after the decimal | if (*pos == '.'){ //only care about after the decimal | |||
for(json_char * runner = pos + 1; *runner; ++runner ){ | for(json_char * runner = pos + 1; *runner; ++runner ){ | |||
if (*runner != JSON_TEXT('0')) pos = runner + 1; | if (*runner != JSON_TEXT('0')) pos = runner + 1; //have to go to the end 1.0001 | |||
} | } | |||
*pos = JSON_TEXT('\0'); | *pos = JSON_TEXT('\0'); | |||
break; | break; | |||
} | } | |||
} | } | |||
return result; | return result; | |||
} | } | |||
static inline bool areEqual(const json_number & one, const json_number & two){ | static inline bool areEqual(const json_number & one, const json_number & two){ | |||
const json_number temp = one - two; | const json_number temp = one - two; | |||
End of changes. 5 change blocks. | ||||
34 lines changed or deleted | 43 lines changed or added | |||