summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKirill Volinsky <mataes2007@gmail.com>2013-02-20 13:26:04 +0000
committerKirill Volinsky <mataes2007@gmail.com>2013-02-20 13:26:04 +0000
commit5c7ba495c74de2d7342ad05c59632b43c1d5321f (patch)
tree0b90c7bb51a8820cfbd494ed99e4ca1efc34d6d3 /src
parentd15942d7c7c07b99c21e5156d6150e19261fe7ee (diff)
small cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@3651 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r--src/modules/json/NumberToString.h178
1 files changed, 89 insertions, 89 deletions
diff --git a/src/modules/json/NumberToString.h b/src/modules/json/NumberToString.h
index cf81f2ef22..177837e50e 100644
--- a/src/modules/json/NumberToString.h
+++ b/src/modules/json/NumberToString.h
@@ -6,99 +6,99 @@
#include <cstdio>
static unsigned int getlen(unsigned int size){
- switch (size){
- case 1:
- return 5; //3 digits for the number, plus null terminator and negation
- case 2:
- return 7; //5 digits for the number, plus null terminator and negation
- case 4:
- return 12; //10 digits for the number, plus null terminator and negation
- case 8:
- return 22; //20 digits for the number, plus null terminator and negation
- }
- JSON_ASSERT(size == 16, JSON_TEXT("template is not recognized 2^x in size"));
- return 41; //39 digits for the number, plus null terminator and negation
+ switch (size){
+ case 1:
+ return 5; //3 digits for the number, plus null terminator and negation
+ case 2:
+ return 7; //5 digits for the number, plus null terminator and negation
+ case 4:
+ return 12; //10 digits for the number, plus null terminator and negation
+ case 8:
+ return 22; //20 digits for the number, plus null terminator and negation
+ }
+ JSON_ASSERT(size == 16, JSON_TEXT("template is not recognized 2^x in size"));
+ return 41; //39 digits for the number, plus null terminator and negation
}
class NumberToString {
public:
- template<typename T>
- static json_string _itoa(T val, unsigned int size){
- long value = (long)val;
- const unsigned int digits = getlen(size);
- json_auto<json_char> result(digits);
- result.ptr[digits - 1] = JSON_TEXT('\0'); //null terminator
- json_char * runner = &result.ptr[digits - 2];
- bool negative;
-
- //first thing, check if it's negative, if so, make it positive
- if (value < 0){
- value = -value;
- negative = true;
- } else {
- negative = false;
- }
-
- //create the string
- do {
- *runner--=(json_char)(value % 10) + JSON_TEXT('0');
- } while(value /= 10);
-
- //if it's negative, add the negation
- json_string res;
- if (negative){
- *runner = JSON_TEXT('-');
- res = runner;
- } else {
- res = runner + 1;
- }
- return res;
- }
-
- #ifndef JSON_LIBRARY
- template<typename T>
- static json_string _uitoa(T val, unsigned int size){
- unsigned long value = val;
- const unsigned int digits = getlen(size) - 1; //minus one because no '-' char
- json_auto<json_char> result(digits);
- result.ptr[digits - 1] = JSON_TEXT('\0'); //null terminator
- json_char * runner = &result.ptr[digits - 2];
-
- //create the string
- do {
- *runner--=(json_char)(value % 10) + JSON_TEXT('0');
- } while(value /= 10);
-
- json_string res = runner + 1;
- return res;
- }
- #endif
-
- template<typename T>
- static json_string _ftoa(T value){
- json_char result[64];
- #ifdef JSON_UNICODE
- swprintf(result, 63, L"%f", value);
- #else
- snprintf(result, 63, "%f", value);
- #endif
- //strip the trailing zeros
- for(json_char * pos = &result[0]; *pos; ++pos){
- if (*pos == '.') { //only care about after the decimal
- for(json_char * runner = pos + 1; *runner; ++runner){
- if (*runner != JSON_TEXT('0')) pos = runner + 1;
- }
- *pos = JSON_TEXT('\0');
- break;
- }
- }
- return result;
- }
-
- static inline bool areEqual(const json_number & one, const json_number & two){
- const json_number temp = one - two;
- return (temp > 0.0) ? temp < 0.00001 : temp > -0.00001;
- }
+ template<typename T>
+ static json_string _itoa(T val, unsigned int size){
+ long value = (long)val;
+ const unsigned int digits = getlen(size);
+ json_auto<json_char> result(digits);
+ result.ptr[digits - 1] = JSON_TEXT('\0'); //null terminator
+ json_char * runner = &result.ptr[digits - 2];
+ bool negative;
+
+ //first thing, check if it's negative, if so, make it positive
+ if (value < 0){
+ value = -value;
+ negative = true;
+ } else {
+ negative = false;
+ }
+
+ //create the string
+ do {
+ *runner--=(json_char)(value % 10) + JSON_TEXT('0');
+ } while(value /= 10);
+
+ //if it's negative, add the negation
+ json_string res;
+ if (negative){
+ *runner = JSON_TEXT('-');
+ res = runner;
+ } else {
+ res = runner + 1;
+ }
+ return res;
+ }
+
+ #ifndef JSON_LIBRARY
+ template<typename T>
+ static json_string _uitoa(T val, unsigned int size){
+ unsigned long value = val;
+ const unsigned int digits = getlen(size) - 1; //minus one because no '-' char
+ json_auto<json_char> result(digits);
+ result.ptr[digits - 1] = JSON_TEXT('\0'); //null terminator
+ json_char * runner = &result.ptr[digits - 2];
+
+ //create the string
+ do {
+ *runner--=(json_char)(value % 10) + JSON_TEXT('0');
+ } while(value /= 10);
+
+ json_string res = runner + 1;
+ return res;
+ }
+ #endif
+
+ template<typename T>
+ static json_string _ftoa(T value){
+ json_char result[64];
+ #ifdef JSON_UNICODE
+ swprintf(result, 63, L"%f", value);
+ #else
+ snprintf(result, 63, "%f", value);
+ #endif
+ //strip the trailing zeros
+ for(json_char * pos = &result[0]; *pos; ++pos){
+ if (*pos == '.') { //only care about after the decimal
+ for(json_char * runner = pos + 1; *runner; ++runner){
+ if (*runner != JSON_TEXT('0')) pos = runner + 1;
+ }
+ *pos = JSON_TEXT('\0');
+ break;
+ }
+ }
+ return result;
+ }
+
+ static inline bool areEqual(const json_number & one, const json_number & two){
+ const json_number temp = one - two;
+ return (temp > 0.0) ? temp < 0.00001 : temp > -0.00001;
+ }
};
#endif