| 298 // the buffer guarantees that we are working on a copied string |
297 // the buffer guarantees that we are working on a copied string |
| 299 char c = str.ptr[str.length]; |
298 char c = str.ptr[str.length]; |
| 300 str.ptr[str.length] = 0; |
299 str.ptr[str.length] = 0; |
| 301 |
300 |
| 302 if (asint) { |
301 if (asint) { |
| |
302 errno = 0; |
| 303 long long v = strtoll(str.ptr, &endptr, 10); |
303 long long v = strtoll(str.ptr, &endptr, 10); |
| |
304 if (errno == ERANGE) { |
| |
305 return 1; |
| |
306 } |
| 304 *((int64_t*)value) = (int64_t) v; |
307 *((int64_t*)value) = (int64_t) v; |
| 305 } else { |
308 } else { |
| 306 // TODO: proper JSON spec number parser |
309 // TODO: proper JSON spec number parser |
| |
310 // TODO: also return an error when loss of precision is high |
| 307 double v = strtod(str.ptr, &endptr); |
311 double v = strtod(str.ptr, &endptr); |
| 308 *((double*)value) = v; |
312 *((double*)value) = v; |
| 309 } |
313 } |
| 310 |
314 |
| 311 // recover from the hack |
315 // recover from the hack |