| 8127 | } |
| 8128 | |
| 8129 | token_type scan() |
| 8130 | { |
| 8131 | // initially, skip the BOM |
| 8132 | if (position.chars_read_total == 0 && !skip_bom()) |
| 8133 | { |
| 8134 | error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given"; |
| 8135 | return token_type::parse_error; |
| 8136 | } |
| 8137 | |
| 8138 | // read next character and ignore whitespace |
| 8139 | skip_whitespace(); |
| 8140 | |
| 8141 | // ignore comments |
| 8142 | while (ignore_comments && current == '/') |
| 8143 | { |
| 8144 | if (!scan_comment()) |
| 8145 | { |
| 8146 | return token_type::parse_error; |
| 8147 | } |
| 8148 | |
| 8149 | // skip following whitespace |
| 8150 | skip_whitespace(); |
| 8151 | } |
| 8152 | |
| 8153 | switch (current) |
| 8154 | { |
| 8155 | // structural characters |
| 8156 | case '[': |
| 8157 | return token_type::begin_array; |
| 8158 | case ']': |
| 8159 | return token_type::end_array; |
| 8160 | case '{': |
| 8161 | return token_type::begin_object; |
| 8162 | case '}': |
| 8163 | return token_type::end_object; |
| 8164 | case ':': |
| 8165 | return token_type::name_separator; |
| 8166 | case ',': |
| 8167 | return token_type::value_separator; |
| 8168 | |
| 8169 | // literals |
| 8170 | case 't': |
| 8171 | { |
| 8172 | std::array<char_type, 4> true_literal = {{char_type('t'), char_type('r'), char_type('u'), char_type('e')}}; |
| 8173 | return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true); |
| 8174 | } |
| 8175 | case 'f': |
| 8176 | { |
| 8177 | std::array<char_type, 5> false_literal = {{char_type('f'), char_type('a'), char_type('l'), char_type('s'), char_type('e')}}; |
| 8178 | return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false); |
| 8179 | } |
| 8180 | case 'n': |
| 8181 | { |
| 8182 | std::array<char_type, 4> null_literal = {{char_type('n'), char_type('u'), char_type('l'), char_type('l')}}; |
| 8183 | return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null); |
| 8184 | } |
| 8185 | |
| 8186 | // string |
nothing calls this directly
no test coverage detected