| 874 | } |
| 875 | |
| 876 | template <typename Context, typename Iter> inline bool _parse(Context &ctx, input<Iter> &in) { |
| 877 | in.skip_ws(); |
| 878 | int ch = in.getc(); |
| 879 | switch (ch) { |
| 880 | #define IS(ch, text, op) \ |
| 881 | case ch: \ |
| 882 | if (in.match(text) && op) { \ |
| 883 | return true; \ |
| 884 | } else { \ |
| 885 | return false; \ |
| 886 | } |
| 887 | IS('n', "ull", ctx.set_null()); |
| 888 | IS('f', "alse", ctx.set_bool(false)); |
| 889 | IS('t', "rue", ctx.set_bool(true)); |
| 890 | #undef IS |
| 891 | case '"': |
| 892 | return ctx.parse_string(in); |
| 893 | case '[': |
| 894 | return _parse_array(ctx, in); |
| 895 | case '{': |
| 896 | return _parse_object(ctx, in); |
| 897 | default: |
| 898 | if (('0' <= ch && ch <= '9') || ch == '-') { |
| 899 | double f; |
| 900 | char *endp; |
| 901 | in.ungetc(); |
| 902 | std::string num_str(_parse_number(in)); |
| 903 | if (num_str.empty()) { |
| 904 | return false; |
| 905 | } |
| 906 | #ifdef PICOJSON_USE_INT64 |
| 907 | { |
| 908 | errno = 0; |
| 909 | intmax_t ival = strtoimax(num_str.c_str(), &endp, 10); |
| 910 | if (errno == 0 && std::numeric_limits<int64_t>::min() <= ival && ival <= std::numeric_limits<int64_t>::max() && |
| 911 | endp == num_str.c_str() + num_str.size()) { |
| 912 | ctx.set_int64(ival); |
| 913 | return true; |
| 914 | } |
| 915 | } |
| 916 | #endif |
| 917 | f = strtod(num_str.c_str(), &endp); |
| 918 | if (endp == num_str.c_str() + num_str.size()) { |
| 919 | ctx.set_number(f); |
| 920 | return true; |
| 921 | } |
| 922 | return false; |
| 923 | } |
| 924 | break; |
| 925 | } |
| 926 | in.ungetc(); |
| 927 | return false; |
| 928 | } |
| 929 | |
| 930 | class deny_parse_context { |
| 931 | public: |
no test coverage detected