Operator Console
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Static Public Member Functions | List of all members
NumberToString Class Reference

#include <NumberToString.h>

Static Public Member Functions

template<typename T >
static json_string _itoa (T val) json_nothrow
 
template<typename T >
static json_string _uitoa (T val) json_nothrow
 
static json_string _ftoa (json_number value) json_nothrow
 
template<typename T >
static json_string _itoa (T val) json_nothrow
 
template<typename T >
static json_string _uitoa (T val) json_nothrow
 
static json_string _ftoa (json_number value) json_nothrow
 

Member Function Documentation

static json_string NumberToString::_ftoa ( json_number  value)
inlinestatic

References _floatsAreEqual(), EXTRA_LONG, FLOAT_STRING, json_char, json_likely, JSON_TEXT, json_unlikely, and LFLOAT_STRING.

126  {
127  #ifndef JSON_LIBRARY
128  //ScopeCoverage(_ftoa_coverage, 6);
129  if (json_unlikely(value >= 0.0 && _floatsAreEqual(value, (json_number)((unsigned EXTRA_LONG long)value)))){
130  //HitScopeCoverage(_ftoa_coverage);
131  return _uitoa<unsigned EXTRA_LONG long>((unsigned EXTRA_LONG long)value);
132  } else
133  #else
134  //ScopeCoverage(_ftoa_coverage, 5);
135  #endif
136  if (json_unlikely(_floatsAreEqual(value, (json_number)((long EXTRA_LONG)value)))){
137  //HitScopeCoverage(_ftoa_coverage);
138  return _itoa<long EXTRA_LONG>((long EXTRA_LONG)value);
139  }
140 
141  #ifdef JSON_LESS_MEMORY
142  json_auto<json_char> s(64);
143  #else
144  json_char num_str_result[64];
145  #endif
146  #ifdef JSON_UNICODE
147  std::swprintf(num_str_result, 63, LFLOAT_STRING, (EXTRA_LONG double)value);
148  #else
149  //Thanks to Salvor Hardin for this Visual C++ fix
150  #ifdef _MSC_VER
151  _snprintf_s(num_str_result, 63, 63, FLOAT_STRING, (EXTRA_LONG double)value); //yes, 63 appears twice using _snprintf_s()
152  #else
153  std::snprintf(num_str_result, 63, FLOAT_STRING, (EXTRA_LONG double)value);
154  #endif
155  #endif
156  //strip the trailing zeros
157  for(json_char * pos = &num_str_result[0]; *pos; ++pos){
158  //HitScopeCoverage(_ftoa_coverage);
159  if (json_unlikely(*pos == '.')){ //only care about after the decimal
160  //HitScopeCoverage(_ftoa_coverage);
161  for(json_char * runner = pos + 1; *runner; ++runner){
162  //HitScopeCoverage(_ftoa_coverage);
163  if (json_likely(*runner != JSON_TEXT('0'))){
164  //HitScopeCoverage(_ftoa_coverage);
165  pos = runner + 1; //have to go to the end 1.0001
166  }
167  }
168  *pos = JSON_TEXT('\0');
169  break;
170  }
171  }
172  return json_string(num_str_result);
173  }
#define JSON_TEXT(s)
Definition: Strings_Defs.h:30
#define json_unlikely(x)
Definition: Unknown_C.h:17
#define FLOAT_STRING
Definition: NumberToString.h:122
#define EXTRA_LONG
Definition: NumberToString.h:121
Definition: JSONMemory.h:129
#define json_char
Definition: Strings_Defs.h:21
double json_number
Definition: JSONDefs.h:91
#define json_likely(x)
Definition: Unknown_C.h:16
#define LFLOAT_STRING
Definition: NumberToString.h:123
static bool _floatsAreEqual(const json_number &one, const json_number &two) json_pure
Definition: NumberToString.h:41

Here is the call graph for this function:

static json_string NumberToString::_ftoa ( json_number  value)
inlinestatic

References _floatsAreEqual(), EXTRA_LONG, FLOAT_STRING, json_char, json_likely, JSON_TEXT, json_unlikely, and LFLOAT_STRING.

126  {
127  #ifndef JSON_LIBRARY
128  //ScopeCoverage(_ftoa_coverage, 6);
129  if (json_unlikely(value >= 0.0 && _floatsAreEqual(value, (json_number)((unsigned EXTRA_LONG long)value)))){
130  //HitScopeCoverage(_ftoa_coverage);
131  return _uitoa<unsigned EXTRA_LONG long>((unsigned EXTRA_LONG long)value);
132  } else
133  #else
134  //ScopeCoverage(_ftoa_coverage, 5);
135  #endif
136  if (json_unlikely(_floatsAreEqual(value, (json_number)((long EXTRA_LONG)value)))){
137  //HitScopeCoverage(_ftoa_coverage);
138  return _itoa<long EXTRA_LONG>((long EXTRA_LONG)value);
139  }
140 
141  #ifdef JSON_LESS_MEMORY
142  json_auto<json_char> s(64);
143  #else
144  json_char num_str_result[64];
145  #endif
146  #ifdef JSON_UNICODE
147  std::swprintf(num_str_result, 63, LFLOAT_STRING, (EXTRA_LONG double)value);
148  #else
149  //Thanks to Salvor Hardin for this Visual C++ fix
150  #ifdef _MSC_VER
151  _snprintf_s(num_str_result, 63, 63, FLOAT_STRING, (EXTRA_LONG double)value); //yes, 63 appears twice using _snprintf_s()
152  #else
153  std::snprintf(num_str_result, 63, FLOAT_STRING, (EXTRA_LONG double)value);
154  #endif
155  #endif
156  //strip the trailing zeros
157  for(json_char * pos = &num_str_result[0]; *pos; ++pos){
158  //HitScopeCoverage(_ftoa_coverage);
159  if (json_unlikely(*pos == '.')){ //only care about after the decimal
160  //HitScopeCoverage(_ftoa_coverage);
161  for(json_char * runner = pos + 1; *runner; ++runner){
162  //HitScopeCoverage(_ftoa_coverage);
163  if (json_likely(*runner != JSON_TEXT('0'))){
164  //HitScopeCoverage(_ftoa_coverage);
165  pos = runner + 1; //have to go to the end 1.0001
166  }
167  }
168  *pos = JSON_TEXT('\0');
169  break;
170  }
171  }
172  return json_string(num_str_result);
173  }
#define JSON_TEXT(s)
Definition: Strings_Defs.h:30
#define LFLOAT_STRING
Definition: NumberToString.h:123
#define json_unlikely(x)
Definition: Unknown_C.h:17
static bool _floatsAreEqual(const json_number &one, const json_number &two) json_pure
Definition: NumberToString.h:41
Definition: JSONMemory.h:129
#define json_char
Definition: Strings_Defs.h:21
#define FLOAT_STRING
Definition: NumberToString.h:122
#define EXTRA_LONG
Definition: NumberToString.h:121
double json_number
Definition: JSONDefs.h:91
#define json_likely(x)
Definition: Unknown_C.h:16

Here is the call graph for this function:

template<typename T >
static json_string NumberToString::_itoa ( val)
inlinestatic

References END_MEM_SCOPE, json_char, JSON_TEXT, and START_MEM_SCOPE.

52  {
53  #ifdef JSON_LESS_MEMORY
54  json_auto<json_char> s(getLenSize<sizeof(T)>::GETLEN);
55  #else
57  #endif
58  num_str_result[getLenSize<sizeof(T)>::GETLEN - 1] = JSON_TEXT('\0'); //null terminator
59  json_char * runner = &num_str_result[getLenSize<sizeof(T)>::GETLEN - 2];
60  bool negative;
61 
63  long value = (long)val;
64  //first thing, check if it's negative, if so, make it positive
65  if (value < 0){
66  //HitScopeCoverage(_itoa_coverage);
67  value = -value;
68  negative = true;
69  } else {
70  //HitScopeCoverage(_itoa_coverage);
71  negative = false;
72  }
73 
74  //create the string
75  do {
76  //HitScopeCoverage(_itoa_coverage);
77  *runner-- = (json_char)(value % 10) + JSON_TEXT('0');
78  } while(value /= 10);
80 
81  //if it's negative, add the negation
82  if (negative){
83  //HitScopeCoverage(_itoa_coverage);
84  *runner = JSON_TEXT('-');
85  return json_string(runner);
86  } else {
87  //HitScopeCoverage(_itoa_coverage);
88  }
89  //HitScopeCoverage(_itoa_coverage);
90  return json_string(runner + 1);
91  }
#define JSON_TEXT(s)
Definition: Strings_Defs.h:30
#define END_MEM_SCOPE
Definition: JSONDefs.h:89
Definition: JSONMemory.h:129
#define START_MEM_SCOPE
Definition: JSONDefs.h:88
#define json_char
Definition: Strings_Defs.h:21
Definition: NumberToString.h:15
template<typename T >
static json_string NumberToString::_itoa ( val)
inlinestatic

References END_MEM_SCOPE, json_char, JSON_TEXT, and START_MEM_SCOPE.

52  {
53  #ifdef JSON_LESS_MEMORY
54  json_auto<json_char> s(getLenSize<sizeof(T)>::GETLEN);
55  #else
57  #endif
58  num_str_result[getLenSize<sizeof(T)>::GETLEN - 1] = JSON_TEXT('\0'); //null terminator
59  json_char * runner = &num_str_result[getLenSize<sizeof(T)>::GETLEN - 2];
60  bool negative;
61 
63  long value = (long)val;
64  //first thing, check if it's negative, if so, make it positive
65  if (value < 0){
66  //HitScopeCoverage(_itoa_coverage);
67  value = -value;
68  negative = true;
69  } else {
70  //HitScopeCoverage(_itoa_coverage);
71  negative = false;
72  }
73 
74  //create the string
75  do {
76  //HitScopeCoverage(_itoa_coverage);
77  *runner-- = (json_char)(value % 10) + JSON_TEXT('0');
78  } while(value /= 10);
80 
81  //if it's negative, add the negation
82  if (negative){
83  //HitScopeCoverage(_itoa_coverage);
84  *runner = JSON_TEXT('-');
85  return json_string(runner);
86  } else {
87  //HitScopeCoverage(_itoa_coverage);
88  }
89  //HitScopeCoverage(_itoa_coverage);
90  return json_string(runner + 1);
91  }
#define JSON_TEXT(s)
Definition: Strings_Defs.h:30
#define END_MEM_SCOPE
Definition: JSONDefs.h:89
Definition: JSONMemory.h:129
#define START_MEM_SCOPE
Definition: JSONDefs.h:88
#define json_char
Definition: Strings_Defs.h:21
Definition: NumberToString.h:15
template<typename T >
static json_string NumberToString::_uitoa ( val)
inlinestatic

References END_MEM_SCOPE, json_char, JSON_TEXT, and START_MEM_SCOPE.

95  {
96  #ifdef JSON_LESS_MEMORY
97  json_auto<json_char> s(getLenSize<sizeof(T)>::GETLEN);
98  #else
100  #endif
101  num_str_result[getLenSize<sizeof(T)>::GETLEN - 1] = JSON_TEXT('\0'); //null terminator
102  json_char * runner = &num_str_result[getLenSize<sizeof(T)>::GETLEN - 2];
103 
104  //create the string
106  unsigned long value = (unsigned long)val;
107  do {
108  *runner-- = (json_char)(value % 10) + JSON_TEXT('0');
109  } while(value /= 10);
111 
112  return json_string(runner + 1);
113  }
#define JSON_TEXT(s)
Definition: Strings_Defs.h:30
#define END_MEM_SCOPE
Definition: JSONDefs.h:89
Definition: JSONMemory.h:129
#define START_MEM_SCOPE
Definition: JSONDefs.h:88
#define json_char
Definition: Strings_Defs.h:21
Definition: NumberToString.h:15
template<typename T >
static json_string NumberToString::_uitoa ( val)
inlinestatic

References END_MEM_SCOPE, json_char, JSON_TEXT, and START_MEM_SCOPE.

95  {
96  #ifdef JSON_LESS_MEMORY
97  json_auto<json_char> s(getLenSize<sizeof(T)>::GETLEN);
98  #else
100  #endif
101  num_str_result[getLenSize<sizeof(T)>::GETLEN - 1] = JSON_TEXT('\0'); //null terminator
102  json_char * runner = &num_str_result[getLenSize<sizeof(T)>::GETLEN - 2];
103 
104  //create the string
106  unsigned long value = (unsigned long)val;
107  do {
108  *runner-- = (json_char)(value % 10) + JSON_TEXT('0');
109  } while(value /= 10);
111 
112  return json_string(runner + 1);
113  }
#define JSON_TEXT(s)
Definition: Strings_Defs.h:30
#define END_MEM_SCOPE
Definition: JSONDefs.h:89
Definition: JSONMemory.h:129
#define START_MEM_SCOPE
Definition: JSONDefs.h:88
#define json_char
Definition: Strings_Defs.h:21
Definition: NumberToString.h:15

The documentation for this class was generated from the following file: