* Convert a string into a number. */
| 420 | * Convert a string into a number. |
| 421 | */ |
| 422 | static intptr_t stringToNumber(const Parser &parser) |
| 423 | { |
| 424 | bool neg = false; |
| 425 | const char *s = parser.s; |
| 426 | if (s[0] == '-') |
| 427 | { |
| 428 | neg = true; |
| 429 | s++; |
| 430 | } |
| 431 | int base = 10; |
| 432 | if (s[0] == '0' && s[1] == 'x') |
| 433 | base = 16; |
| 434 | char *end = nullptr; |
| 435 | errno = 0; |
| 436 | intptr_t x = (intptr_t)strtoull(s, &end, base); |
| 437 | if (errno != 0 || (end != nullptr && *end != '\0')) |
| 438 | parse_error(parser, "failed to parse number from JSON string \"%s\"", |
| 439 | parser.s); |
| 440 | return (neg? -x: x); |
| 441 | } |
| 442 | |
| 443 | /* |
| 444 | * Expect the specific string token. |
no test coverage detected