| 580 | } |
| 581 | |
| 582 | template <typename Context, typename Iter> bool _parse(Context &ctx, input<Iter> &in) |
| 583 | { |
| 584 | in.skip_ws(); |
| 585 | int ch = in.getc(); |
| 586 | switch (ch) { |
| 587 | #define IS(ch, text, op) \ |
| 588 | case ch: \ |
| 589 | if (in.match(text) && op) { \ |
| 590 | return true; \ |
| 591 | } else { \ |
| 592 | return false; \ |
| 593 | } |
| 594 | IS('n', "ull", ctx.set_null()); |
| 595 | IS('f', "alse", ctx.set_bool(false)); |
| 596 | IS('t', "rue", ctx.set_bool(true)); |
| 597 | #undef IS |
| 598 | case '"': |
| 599 | return ctx.parse_string(in); |
| 600 | case '[': |
| 601 | return _parse_array(ctx, in); |
| 602 | case '{': |
| 603 | return _parse_object(ctx, in); |
| 604 | default: |
| 605 | if (('0' <= ch && ch <= '9') || ch == '-') { |
| 606 | double f; |
| 607 | char *endp; |
| 608 | in.ungetc(); |
| 609 | std::string num_str(_parse_number(in)); |
| 610 | if (num_str.empty()) { |
| 611 | return false; |
| 612 | } |
| 613 | f = strtod(num_str.c_str(), &endp); |
| 614 | if (endp == num_str.c_str() + num_str.size()) { |
| 615 | ctx.set_number(f); |
| 616 | return true; |
| 617 | } |
| 618 | return false; |
| 619 | } |
| 620 | break; |
| 621 | } |
| 622 | in.ungetc(); |
| 623 | return false; |
| 624 | } |
| 625 | |
| 626 | class default_parse_context |
| 627 | { |
no test coverage detected