All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Functions
rapidjson::internal Namespace Reference

Classes

struct  DiyFp
 
struct  IsGenericValue
 
struct  IsGenericValueImpl
 
struct  IsGenericValueImpl< T, typename Void< typename T::EncodingType >::Type, typename Void< typename T::AllocatorType >::Type >
 
class  Stack
 A type-unsafe stack for storing different types of data. More...
 
class  StreamLocalCopy
 
class  StreamLocalCopy< Stream, 0 >
 Keep reference. More...
 
class  StreamLocalCopy< Stream, 1 >
 Do copy optimization. More...
 

Functions

DiyFp GetCachedPower (int e, int *K)
 
void GrisuRound (char *buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w)
 
unsigned CountDecimalDigit32 (uint32_t n)
 
void DigitGen (const DiyFp &W, const DiyFp &Mp, uint64_t delta, char *buffer, int *len, int *K)
 
void Grisu2 (double value, char *buffer, int *length, int *K)
 
char * WriteExponent (int K, char *buffer)
 
char * Prettify (char *buffer, int length, int k)
 
char * dtoa (double value, char *buffer)
 
const char * GetDigitsLut ()
 
char * u32toa (uint32_t value, char *buffer)
 
char * i32toa (int32_t value, char *buffer)
 
char * u64toa (uint64_t value, char *buffer)
 
char * i64toa (int64_t value, char *buffer)
 
double Pow10 (int n)
 Computes integer powers of 10 in double (10.0^n). More...
 
template<typename Ch >
SizeType StrLen (const Ch *s)
 Custom strlen() which works on different character types. More...
 

Function Documentation

unsigned rapidjson::internal::CountDecimalDigit32 ( uint32_t  n)
inline

Definition at line 241 of file dtoa.h.

241  {
242  // Simple pure C++ implementation was faster than __builtin_clz version in this situation.
243  if (n < 10) return 1;
244  if (n < 100) return 2;
245  if (n < 1000) return 3;
246  if (n < 10000) return 4;
247  if (n < 100000) return 5;
248  if (n < 1000000) return 6;
249  if (n < 10000000) return 7;
250  if (n < 100000000) return 8;
251  if (n < 1000000000) return 9;
252  return 10;
253 }
void rapidjson::internal::DigitGen ( const DiyFp W,
const DiyFp Mp,
uint64_t  delta,
char *  buffer,
int *  len,
int *  K 
)
inline

Definition at line 255 of file dtoa.h.

255  {
256  static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
257  const DiyFp one(uint64_t(1) << -Mp.e, Mp.e);
258  const DiyFp wp_w = Mp - W;
259  uint32_t p1 = static_cast<uint32_t>(Mp.f >> -one.e);
260  uint64_t p2 = Mp.f & (one.f - 1);
261  int kappa = CountDecimalDigit32(p1);
262  *len = 0;
263 
264  while (kappa > 0) {
265  uint32_t d;
266  switch (kappa) {
267  case 10: d = p1 / 1000000000; p1 %= 1000000000; break;
268  case 9: d = p1 / 100000000; p1 %= 100000000; break;
269  case 8: d = p1 / 10000000; p1 %= 10000000; break;
270  case 7: d = p1 / 1000000; p1 %= 1000000; break;
271  case 6: d = p1 / 100000; p1 %= 100000; break;
272  case 5: d = p1 / 10000; p1 %= 10000; break;
273  case 4: d = p1 / 1000; p1 %= 1000; break;
274  case 3: d = p1 / 100; p1 %= 100; break;
275  case 2: d = p1 / 10; p1 %= 10; break;
276  case 1: d = p1; p1 = 0; break;
277  default:
278 #if defined(_MSC_VER)
279  __assume(0);
280 #elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
281  __builtin_unreachable();
282 #else
283  d = 0;
284 #endif
285  }
286  if (d || *len)
287  buffer[(*len)++] = static_cast<char>('0' + static_cast<char>(d));
288  kappa--;
289  uint64_t tmp = (static_cast<uint64_t>(p1) << -one.e) + p2;
290  if (tmp <= delta) {
291  *K += kappa;
292  GrisuRound(buffer, *len, delta, tmp, static_cast<uint64_t>(kPow10[kappa]) << -one.e, wp_w.f);
293  return;
294  }
295  }
296 
297  // kappa = 0
298  for (;;) {
299  p2 *= 10;
300  delta *= 10;
301  char d = static_cast<char>(p2 >> -one.e);
302  if (d || *len)
303  buffer[(*len)++] = static_cast<char>('0' + d);
304  p2 &= one.f - 1;
305  kappa--;
306  if (p2 < delta) {
307  *K += kappa;
308  GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * kPow10[-kappa]);
309  return;
310  }
311  }
312 }
unsigned CountDecimalDigit32(uint32_t n)
Definition: dtoa.h:241
unsigned int uint32_t
Definition: stdint.h:122
unsigned __int64 uint64_t
Definition: stdint.h:132
static std::complex< double > one(1.0, 0.0)
void GrisuRound(char *buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w)
Definition: dtoa.h:232
char* rapidjson::internal::dtoa ( double  value,
char *  buffer 
)
inline

Definition at line 393 of file dtoa.h.

393  {
394  if (value == 0) {
395  buffer[0] = '0';
396  buffer[1] = '.';
397  buffer[2] = '0';
398  return &buffer[3];
399  }
400  else {
401  if (value < 0) {
402  *buffer++ = '-';
403  value = -value;
404  }
405  int length, K;
406  Grisu2(value, buffer, &length, &K);
407  return Prettify(buffer, length, K);
408  }
409 }
void Grisu2(double value, char *buffer, int *length, int *K)
Definition: dtoa.h:314
char * Prettify(char *buffer, int length, int k)
Definition: dtoa.h:352
DiyFp rapidjson::internal::GetCachedPower ( int  e,
int *  K 
)
inline

Definition at line 160 of file dtoa.h.

160  {
161  // 10^-348, 10^-340, ..., 10^340
162  static const uint64_t kCachedPowers_F[] = {
163  RAPIDJSON_UINT64_C2(0xfa8fd5a0, 0x081c0288), RAPIDJSON_UINT64_C2(0xbaaee17f, 0xa23ebf76),
164  RAPIDJSON_UINT64_C2(0x8b16fb20, 0x3055ac76), RAPIDJSON_UINT64_C2(0xcf42894a, 0x5dce35ea),
165  RAPIDJSON_UINT64_C2(0x9a6bb0aa, 0x55653b2d), RAPIDJSON_UINT64_C2(0xe61acf03, 0x3d1a45df),
166  RAPIDJSON_UINT64_C2(0xab70fe17, 0xc79ac6ca), RAPIDJSON_UINT64_C2(0xff77b1fc, 0xbebcdc4f),
167  RAPIDJSON_UINT64_C2(0xbe5691ef, 0x416bd60c), RAPIDJSON_UINT64_C2(0x8dd01fad, 0x907ffc3c),
168  RAPIDJSON_UINT64_C2(0xd3515c28, 0x31559a83), RAPIDJSON_UINT64_C2(0x9d71ac8f, 0xada6c9b5),
169  RAPIDJSON_UINT64_C2(0xea9c2277, 0x23ee8bcb), RAPIDJSON_UINT64_C2(0xaecc4991, 0x4078536d),
170  RAPIDJSON_UINT64_C2(0x823c1279, 0x5db6ce57), RAPIDJSON_UINT64_C2(0xc2109436, 0x4dfb5637),
171  RAPIDJSON_UINT64_C2(0x9096ea6f, 0x3848984f), RAPIDJSON_UINT64_C2(0xd77485cb, 0x25823ac7),
172  RAPIDJSON_UINT64_C2(0xa086cfcd, 0x97bf97f4), RAPIDJSON_UINT64_C2(0xef340a98, 0x172aace5),
173  RAPIDJSON_UINT64_C2(0xb23867fb, 0x2a35b28e), RAPIDJSON_UINT64_C2(0x84c8d4df, 0xd2c63f3b),
174  RAPIDJSON_UINT64_C2(0xc5dd4427, 0x1ad3cdba), RAPIDJSON_UINT64_C2(0x936b9fce, 0xbb25c996),
175  RAPIDJSON_UINT64_C2(0xdbac6c24, 0x7d62a584), RAPIDJSON_UINT64_C2(0xa3ab6658, 0x0d5fdaf6),
176  RAPIDJSON_UINT64_C2(0xf3e2f893, 0xdec3f126), RAPIDJSON_UINT64_C2(0xb5b5ada8, 0xaaff80b8),
177  RAPIDJSON_UINT64_C2(0x87625f05, 0x6c7c4a8b), RAPIDJSON_UINT64_C2(0xc9bcff60, 0x34c13053),
178  RAPIDJSON_UINT64_C2(0x964e858c, 0x91ba2655), RAPIDJSON_UINT64_C2(0xdff97724, 0x70297ebd),
179  RAPIDJSON_UINT64_C2(0xa6dfbd9f, 0xb8e5b88f), RAPIDJSON_UINT64_C2(0xf8a95fcf, 0x88747d94),
180  RAPIDJSON_UINT64_C2(0xb9447093, 0x8fa89bcf), RAPIDJSON_UINT64_C2(0x8a08f0f8, 0xbf0f156b),
181  RAPIDJSON_UINT64_C2(0xcdb02555, 0x653131b6), RAPIDJSON_UINT64_C2(0x993fe2c6, 0xd07b7fac),
182  RAPIDJSON_UINT64_C2(0xe45c10c4, 0x2a2b3b06), RAPIDJSON_UINT64_C2(0xaa242499, 0x697392d3),
183  RAPIDJSON_UINT64_C2(0xfd87b5f2, 0x8300ca0e), RAPIDJSON_UINT64_C2(0xbce50864, 0x92111aeb),
184  RAPIDJSON_UINT64_C2(0x8cbccc09, 0x6f5088cc), RAPIDJSON_UINT64_C2(0xd1b71758, 0xe219652c),
185  RAPIDJSON_UINT64_C2(0x9c400000, 0x00000000), RAPIDJSON_UINT64_C2(0xe8d4a510, 0x00000000),
186  RAPIDJSON_UINT64_C2(0xad78ebc5, 0xac620000), RAPIDJSON_UINT64_C2(0x813f3978, 0xf8940984),
187  RAPIDJSON_UINT64_C2(0xc097ce7b, 0xc90715b3), RAPIDJSON_UINT64_C2(0x8f7e32ce, 0x7bea5c70),
188  RAPIDJSON_UINT64_C2(0xd5d238a4, 0xabe98068), RAPIDJSON_UINT64_C2(0x9f4f2726, 0x179a2245),
189  RAPIDJSON_UINT64_C2(0xed63a231, 0xd4c4fb27), RAPIDJSON_UINT64_C2(0xb0de6538, 0x8cc8ada8),
190  RAPIDJSON_UINT64_C2(0x83c7088e, 0x1aab65db), RAPIDJSON_UINT64_C2(0xc45d1df9, 0x42711d9a),
191  RAPIDJSON_UINT64_C2(0x924d692c, 0xa61be758), RAPIDJSON_UINT64_C2(0xda01ee64, 0x1a708dea),
192  RAPIDJSON_UINT64_C2(0xa26da399, 0x9aef774a), RAPIDJSON_UINT64_C2(0xf209787b, 0xb47d6b85),
193  RAPIDJSON_UINT64_C2(0xb454e4a1, 0x79dd1877), RAPIDJSON_UINT64_C2(0x865b8692, 0x5b9bc5c2),
194  RAPIDJSON_UINT64_C2(0xc83553c5, 0xc8965d3d), RAPIDJSON_UINT64_C2(0x952ab45c, 0xfa97a0b3),
195  RAPIDJSON_UINT64_C2(0xde469fbd, 0x99a05fe3), RAPIDJSON_UINT64_C2(0xa59bc234, 0xdb398c25),
196  RAPIDJSON_UINT64_C2(0xf6c69a72, 0xa3989f5c), RAPIDJSON_UINT64_C2(0xb7dcbf53, 0x54e9bece),
197  RAPIDJSON_UINT64_C2(0x88fcf317, 0xf22241e2), RAPIDJSON_UINT64_C2(0xcc20ce9b, 0xd35c78a5),
198  RAPIDJSON_UINT64_C2(0x98165af3, 0x7b2153df), RAPIDJSON_UINT64_C2(0xe2a0b5dc, 0x971f303a),
199  RAPIDJSON_UINT64_C2(0xa8d9d153, 0x5ce3b396), RAPIDJSON_UINT64_C2(0xfb9b7cd9, 0xa4a7443c),
200  RAPIDJSON_UINT64_C2(0xbb764c4c, 0xa7a44410), RAPIDJSON_UINT64_C2(0x8bab8eef, 0xb6409c1a),
201  RAPIDJSON_UINT64_C2(0xd01fef10, 0xa657842c), RAPIDJSON_UINT64_C2(0x9b10a4e5, 0xe9913129),
202  RAPIDJSON_UINT64_C2(0xe7109bfb, 0xa19c0c9d), RAPIDJSON_UINT64_C2(0xac2820d9, 0x623bf429),
203  RAPIDJSON_UINT64_C2(0x80444b5e, 0x7aa7cf85), RAPIDJSON_UINT64_C2(0xbf21e440, 0x03acdd2d),
204  RAPIDJSON_UINT64_C2(0x8e679c2f, 0x5e44ff8f), RAPIDJSON_UINT64_C2(0xd433179d, 0x9c8cb841),
205  RAPIDJSON_UINT64_C2(0x9e19db92, 0xb4e31ba9), RAPIDJSON_UINT64_C2(0xeb96bf6e, 0xbadf77d9),
206  RAPIDJSON_UINT64_C2(0xaf87023b, 0x9bf0ee6b)
207  };
208  static const int16_t kCachedPowers_E[] = {
209  -1220, -1193, -1166, -1140, -1113, -1087, -1060, -1034, -1007, -980,
210  -954, -927, -901, -874, -847, -821, -794, -768, -741, -715,
211  -688, -661, -635, -608, -582, -555, -529, -502, -475, -449,
212  -422, -396, -369, -343, -316, -289, -263, -236, -210, -183,
213  -157, -130, -103, -77, -50, -24, 3, 30, 56, 83,
214  109, 136, 162, 189, 216, 242, 269, 295, 322, 348,
215  375, 402, 428, 455, 481, 508, 534, 561, 588, 614,
216  641, 667, 694, 720, 747, 774, 800, 827, 853, 880,
217  907, 933, 960, 986, 1013, 1039, 1066
218  };
219 
220  //int k = static_cast<int>(ceil((-61 - e) * 0.30102999566398114)) + 374;
221  double dk = (-61 - e) * 0.30102999566398114 + 347; // dk must be positive, so can do ceiling in positive
222  int k = static_cast<int>(dk);
223  if (k != dk)
224  k++;
225 
226  unsigned index = static_cast<unsigned>((k >> 3) + 1);
227  *K = -(-348 + static_cast<int>(index << 3)); // decimal exponent no need lookup table
228 
229  return DiyFp(kCachedPowers_F[index], kCachedPowers_E[index]);
230 }
#define RAPIDJSON_UINT64_C2(high32, low32)
Construct a 64-bit literal by a pair of 32-bit integer.
Definition: rapidjson.h:186
const double e
signed short int16_t
Definition: stdint.h:118
unsigned __int64 uint64_t
Definition: stdint.h:132
const char* rapidjson::internal::GetDigitsLut ( )
inline

Definition at line 27 of file itoa.h.

27  {
28  static const char cDigitsLut[200] = {
29  '0','0','0','1','0','2','0','3','0','4','0','5','0','6','0','7','0','8','0','9',
30  '1','0','1','1','1','2','1','3','1','4','1','5','1','6','1','7','1','8','1','9',
31  '2','0','2','1','2','2','2','3','2','4','2','5','2','6','2','7','2','8','2','9',
32  '3','0','3','1','3','2','3','3','3','4','3','5','3','6','3','7','3','8','3','9',
33  '4','0','4','1','4','2','4','3','4','4','4','5','4','6','4','7','4','8','4','9',
34  '5','0','5','1','5','2','5','3','5','4','5','5','5','6','5','7','5','8','5','9',
35  '6','0','6','1','6','2','6','3','6','4','6','5','6','6','6','7','6','8','6','9',
36  '7','0','7','1','7','2','7','3','7','4','7','5','7','6','7','7','7','8','7','9',
37  '8','0','8','1','8','2','8','3','8','4','8','5','8','6','8','7','8','8','8','9',
38  '9','0','9','1','9','2','9','3','9','4','9','5','9','6','9','7','9','8','9','9'
39  };
40  return cDigitsLut;
41 }
void rapidjson::internal::Grisu2 ( double  value,
char *  buffer,
int *  length,
int *  K 
)
inline

Definition at line 314 of file dtoa.h.

314  {
315  const DiyFp v(value);
316  DiyFp w_m, w_p;
317  v.NormalizedBoundaries(&w_m, &w_p);
318 
319  const DiyFp c_mk = GetCachedPower(w_p.e, K);
320  const DiyFp W = v.Normalize() * c_mk;
321  DiyFp Wp = w_p * c_mk;
322  DiyFp Wm = w_m * c_mk;
323  Wm.f++;
324  Wp.f--;
325  DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K);
326 }
DiyFp GetCachedPower(int e, int *K)
Definition: dtoa.h:160
void DigitGen(const DiyFp &W, const DiyFp &Mp, uint64_t delta, char *buffer, int *len, int *K)
Definition: dtoa.h:255
void rapidjson::internal::GrisuRound ( char *  buffer,
int  len,
uint64_t  delta,
uint64_t  rest,
uint64_t  ten_kappa,
uint64_t  wp_w 
)
inline

closer

Definition at line 232 of file dtoa.h.

232  {
233  while (rest < wp_w && delta - rest >= ten_kappa &&
234  (rest + ten_kappa < wp_w || /// closer
235  wp_w - rest > rest + ten_kappa - wp_w)) {
236  buffer[len - 1]--;
237  rest += ten_kappa;
238  }
239 }
char* rapidjson::internal::i32toa ( int32_t  value,
char *  buffer 
)
inline

Definition at line 117 of file itoa.h.

117  {
118  if (value < 0) {
119  *buffer++ = '-';
120  value = -value;
121  }
122 
123  return u32toa(static_cast<uint32_t>(value), buffer);
124 }
char * u32toa(uint32_t value, char *buffer)
Definition: itoa.h:43
char* rapidjson::internal::i64toa ( int64_t  value,
char *  buffer 
)
inline

Definition at line 294 of file itoa.h.

294  {
295  if (value < 0) {
296  *buffer++ = '-';
297  value = -value;
298  }
299 
300  return u64toa(static_cast<uint64_t>(value), buffer);
301 }
char * u64toa(uint64_t value, char *buffer)
Definition: itoa.h:126
double rapidjson::internal::Pow10 ( int  n)
inline

Computes integer powers of 10 in double (10.0^n).

This function uses lookup table for fast and accurate results.

Parameters
nnon-negative exponent. Must <= 308.
Returns
10.0^n

Definition at line 32 of file pow10.h.

32  {
33  static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes
34  1e+0,
35  1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20,
36  1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40,
37  1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60,
38  1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80,
39  1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100,
40  1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120,
41  1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140,
42  1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160,
43  1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180,
44  1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200,
45  1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220,
46  1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240,
47  1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260,
48  1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280,
49  1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300,
50  1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308
51  };
52  RAPIDJSON_ASSERT(n >= 0 && n <= 308);
53  return e[n];
54 }
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:269
const double e
char* rapidjson::internal::Prettify ( char *  buffer,
int  length,
int  k 
)
inline

Definition at line 352 of file dtoa.h.

352  {
353  const int kk = length + k; // 10^(kk-1) <= v < 10^kk
354 
355  if (length <= kk && kk <= 21) {
356  // 1234e7 -> 12340000000
357  for (int i = length; i < kk; i++)
358  buffer[i] = '0';
359  buffer[kk] = '.';
360  buffer[kk + 1] = '0';
361  return &buffer[kk + 2];
362  }
363  else if (0 < kk && kk <= 21) {
364  // 1234e-2 -> 12.34
365  std::memmove(&buffer[kk + 1], &buffer[kk], length - kk);
366  buffer[kk] = '.';
367  return &buffer[length + 1];
368  }
369  else if (-6 < kk && kk <= 0) {
370  // 1234e-6 -> 0.001234
371  const int offset = 2 - kk;
372  std::memmove(&buffer[offset], &buffer[0], length);
373  buffer[0] = '0';
374  buffer[1] = '.';
375  for (int i = 2; i < offset; i++)
376  buffer[i] = '0';
377  return &buffer[length + offset];
378  }
379  else if (length == 1) {
380  // 1e30
381  buffer[1] = 'e';
382  return WriteExponent(kk - 1, &buffer[2]);
383  }
384  else {
385  // 1234e30 -> 1.234e33
386  std::memmove(&buffer[2], &buffer[1], length - 1);
387  buffer[1] = '.';
388  buffer[length + 1] = 'e';
389  return WriteExponent(kk - 1, &buffer[0 + length + 2]);
390  }
391 }
char * WriteExponent(int K, char *buffer)
Definition: dtoa.h:328
template<typename Ch >
SizeType rapidjson::internal::StrLen ( const Ch *  s)
inline

Custom strlen() which works on different character types.

Template Parameters
ChCharacter type (e.g. char, wchar_t, short)
Parameters
sNull-terminated input string.
Returns
Number of characters in the string.
Note
This has the same semantics as strlen(), the return value is not number of Unicode codepoints.

Definition at line 34 of file strfunc.h.

34  {
35  const Ch* p = s;
36  while (*p) ++p;
37  return SizeType(p - s);
38 }
unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:247
p
Definition: test.py:228
static const double s
Definition: Units.h:99
char* rapidjson::internal::u32toa ( uint32_t  value,
char *  buffer 
)
inline

Definition at line 43 of file itoa.h.

43  {
44  const char* cDigitsLut = GetDigitsLut();
45 
46  if (value < 10000) {
47  const uint32_t d1 = (value / 100) << 1;
48  const uint32_t d2 = (value % 100) << 1;
49 
50  if (value >= 1000)
51  *buffer++ = cDigitsLut[d1];
52  if (value >= 100)
53  *buffer++ = cDigitsLut[d1 + 1];
54  if (value >= 10)
55  *buffer++ = cDigitsLut[d2];
56  *buffer++ = cDigitsLut[d2 + 1];
57  }
58  else if (value < 100000000) {
59  // value = bbbbcccc
60  const uint32_t b = value / 10000;
61  const uint32_t c = value % 10000;
62 
63  const uint32_t d1 = (b / 100) << 1;
64  const uint32_t d2 = (b % 100) << 1;
65 
66  const uint32_t d3 = (c / 100) << 1;
67  const uint32_t d4 = (c % 100) << 1;
68 
69  if (value >= 10000000)
70  *buffer++ = cDigitsLut[d1];
71  if (value >= 1000000)
72  *buffer++ = cDigitsLut[d1 + 1];
73  if (value >= 100000)
74  *buffer++ = cDigitsLut[d2];
75  *buffer++ = cDigitsLut[d2 + 1];
76 
77  *buffer++ = cDigitsLut[d3];
78  *buffer++ = cDigitsLut[d3 + 1];
79  *buffer++ = cDigitsLut[d4];
80  *buffer++ = cDigitsLut[d4 + 1];
81  }
82  else {
83  // value = aabbbbcccc in decimal
84 
85  const uint32_t a = value / 100000000; // 1 to 42
86  value %= 100000000;
87 
88  if (a >= 10) {
89  const unsigned i = a << 1;
90  *buffer++ = cDigitsLut[i];
91  *buffer++ = cDigitsLut[i + 1];
92  }
93  else
94  *buffer++ = static_cast<char>('0' + static_cast<char>(a));
95 
96  const uint32_t b = value / 10000; // 0 to 9999
97  const uint32_t c = value % 10000; // 0 to 9999
98 
99  const uint32_t d1 = (b / 100) << 1;
100  const uint32_t d2 = (b % 100) << 1;
101 
102  const uint32_t d3 = (c / 100) << 1;
103  const uint32_t d4 = (c % 100) << 1;
104 
105  *buffer++ = cDigitsLut[d1];
106  *buffer++ = cDigitsLut[d1 + 1];
107  *buffer++ = cDigitsLut[d2];
108  *buffer++ = cDigitsLut[d2 + 1];
109  *buffer++ = cDigitsLut[d3];
110  *buffer++ = cDigitsLut[d3 + 1];
111  *buffer++ = cDigitsLut[d4];
112  *buffer++ = cDigitsLut[d4 + 1];
113  }
114  return buffer;
115 }
unsigned int uint32_t
Definition: stdint.h:122
const double a
const char * GetDigitsLut()
Definition: itoa.h:27
char* rapidjson::internal::u64toa ( uint64_t  value,
char *  buffer 
)
inline

Definition at line 126 of file itoa.h.

126  {
127  const char* cDigitsLut = GetDigitsLut();
128  const uint64_t kTen8 = 100000000;
129  const uint64_t kTen9 = kTen8 * 10;
130  const uint64_t kTen10 = kTen8 * 100;
131  const uint64_t kTen11 = kTen8 * 1000;
132  const uint64_t kTen12 = kTen8 * 10000;
133  const uint64_t kTen13 = kTen8 * 100000;
134  const uint64_t kTen14 = kTen8 * 1000000;
135  const uint64_t kTen15 = kTen8 * 10000000;
136  const uint64_t kTen16 = kTen8 * kTen8;
137 
138  if (value < kTen8) {
139  uint32_t v = static_cast<uint32_t>(value);
140  if (v < 10000) {
141  const uint32_t d1 = (v / 100) << 1;
142  const uint32_t d2 = (v % 100) << 1;
143 
144  if (v >= 1000)
145  *buffer++ = cDigitsLut[d1];
146  if (v >= 100)
147  *buffer++ = cDigitsLut[d1 + 1];
148  if (v >= 10)
149  *buffer++ = cDigitsLut[d2];
150  *buffer++ = cDigitsLut[d2 + 1];
151  }
152  else {
153  // value = bbbbcccc
154  const uint32_t b = v / 10000;
155  const uint32_t c = v % 10000;
156 
157  const uint32_t d1 = (b / 100) << 1;
158  const uint32_t d2 = (b % 100) << 1;
159 
160  const uint32_t d3 = (c / 100) << 1;
161  const uint32_t d4 = (c % 100) << 1;
162 
163  if (value >= 10000000)
164  *buffer++ = cDigitsLut[d1];
165  if (value >= 1000000)
166  *buffer++ = cDigitsLut[d1 + 1];
167  if (value >= 100000)
168  *buffer++ = cDigitsLut[d2];
169  *buffer++ = cDigitsLut[d2 + 1];
170 
171  *buffer++ = cDigitsLut[d3];
172  *buffer++ = cDigitsLut[d3 + 1];
173  *buffer++ = cDigitsLut[d4];
174  *buffer++ = cDigitsLut[d4 + 1];
175  }
176  }
177  else if (value < kTen16) {
178  const uint32_t v0 = static_cast<uint32_t>(value / kTen8);
179  const uint32_t v1 = static_cast<uint32_t>(value % kTen8);
180 
181  const uint32_t b0 = v0 / 10000;
182  const uint32_t c0 = v0 % 10000;
183 
184  const uint32_t d1 = (b0 / 100) << 1;
185  const uint32_t d2 = (b0 % 100) << 1;
186 
187  const uint32_t d3 = (c0 / 100) << 1;
188  const uint32_t d4 = (c0 % 100) << 1;
189 
190  const uint32_t b1 = v1 / 10000;
191  const uint32_t c1 = v1 % 10000;
192 
193  const uint32_t d5 = (b1 / 100) << 1;
194  const uint32_t d6 = (b1 % 100) << 1;
195 
196  const uint32_t d7 = (c1 / 100) << 1;
197  const uint32_t d8 = (c1 % 100) << 1;
198 
199  if (value >= kTen15)
200  *buffer++ = cDigitsLut[d1];
201  if (value >= kTen14)
202  *buffer++ = cDigitsLut[d1 + 1];
203  if (value >= kTen13)
204  *buffer++ = cDigitsLut[d2];
205  if (value >= kTen12)
206  *buffer++ = cDigitsLut[d2 + 1];
207  if (value >= kTen11)
208  *buffer++ = cDigitsLut[d3];
209  if (value >= kTen10)
210  *buffer++ = cDigitsLut[d3 + 1];
211  if (value >= kTen9)
212  *buffer++ = cDigitsLut[d4];
213  if (value >= kTen8)
214  *buffer++ = cDigitsLut[d4 + 1];
215 
216  *buffer++ = cDigitsLut[d5];
217  *buffer++ = cDigitsLut[d5 + 1];
218  *buffer++ = cDigitsLut[d6];
219  *buffer++ = cDigitsLut[d6 + 1];
220  *buffer++ = cDigitsLut[d7];
221  *buffer++ = cDigitsLut[d7 + 1];
222  *buffer++ = cDigitsLut[d8];
223  *buffer++ = cDigitsLut[d8 + 1];
224  }
225  else {
226  const uint32_t a = static_cast<uint32_t>(value / kTen16); // 1 to 1844
227  value %= kTen16;
228 
229  if (a < 10)
230  *buffer++ = static_cast<char>('0' + static_cast<char>(a));
231  else if (a < 100) {
232  const uint32_t i = a << 1;
233  *buffer++ = cDigitsLut[i];
234  *buffer++ = cDigitsLut[i + 1];
235  }
236  else if (a < 1000) {
237  *buffer++ = static_cast<char>('0' + static_cast<char>(a / 100));
238 
239  const uint32_t i = (a % 100) << 1;
240  *buffer++ = cDigitsLut[i];
241  *buffer++ = cDigitsLut[i + 1];
242  }
243  else {
244  const uint32_t i = (a / 100) << 1;
245  const uint32_t j = (a % 100) << 1;
246  *buffer++ = cDigitsLut[i];
247  *buffer++ = cDigitsLut[i + 1];
248  *buffer++ = cDigitsLut[j];
249  *buffer++ = cDigitsLut[j + 1];
250  }
251 
252  const uint32_t v0 = static_cast<uint32_t>(value / kTen8);
253  const uint32_t v1 = static_cast<uint32_t>(value % kTen8);
254 
255  const uint32_t b0 = v0 / 10000;
256  const uint32_t c0 = v0 % 10000;
257 
258  const uint32_t d1 = (b0 / 100) << 1;
259  const uint32_t d2 = (b0 % 100) << 1;
260 
261  const uint32_t d3 = (c0 / 100) << 1;
262  const uint32_t d4 = (c0 % 100) << 1;
263 
264  const uint32_t b1 = v1 / 10000;
265  const uint32_t c1 = v1 % 10000;
266 
267  const uint32_t d5 = (b1 / 100) << 1;
268  const uint32_t d6 = (b1 % 100) << 1;
269 
270  const uint32_t d7 = (c1 / 100) << 1;
271  const uint32_t d8 = (c1 % 100) << 1;
272 
273  *buffer++ = cDigitsLut[d1];
274  *buffer++ = cDigitsLut[d1 + 1];
275  *buffer++ = cDigitsLut[d2];
276  *buffer++ = cDigitsLut[d2 + 1];
277  *buffer++ = cDigitsLut[d3];
278  *buffer++ = cDigitsLut[d3 + 1];
279  *buffer++ = cDigitsLut[d4];
280  *buffer++ = cDigitsLut[d4 + 1];
281  *buffer++ = cDigitsLut[d5];
282  *buffer++ = cDigitsLut[d5 + 1];
283  *buffer++ = cDigitsLut[d6];
284  *buffer++ = cDigitsLut[d6 + 1];
285  *buffer++ = cDigitsLut[d7];
286  *buffer++ = cDigitsLut[d7 + 1];
287  *buffer++ = cDigitsLut[d8];
288  *buffer++ = cDigitsLut[d8 + 1];
289  }
290 
291  return buffer;
292 }
unsigned int uint32_t
Definition: stdint.h:122
const double a
unsigned __int64 uint64_t
Definition: stdint.h:132
const char * GetDigitsLut()
Definition: itoa.h:27
char* rapidjson::internal::WriteExponent ( int  K,
char *  buffer 
)
inline

Definition at line 328 of file dtoa.h.

328  {
329  if (K < 0) {
330  *buffer++ = '-';
331  K = -K;
332  }
333 
334  if (K >= 100) {
335  *buffer++ = static_cast<char>('0' + static_cast<char>(K / 100));
336  K %= 100;
337  const char* d = GetDigitsLut() + K * 2;
338  *buffer++ = d[0];
339  *buffer++ = d[1];
340  }
341  else if (K >= 10) {
342  const char* d = GetDigitsLut() + K * 2;
343  *buffer++ = d[0];
344  *buffer++ = d[1];
345  }
346  else
347  *buffer++ = static_cast<char>('0' + static_cast<char>(K));
348 
349  return buffer;
350 }
const char * GetDigitsLut()
Definition: itoa.h:27