Commit a7338ab15ae6209dbdefb7121b9051cb8ede5fa2
1 parent
4dba3c95
In JSONParser::handleToken move processing for ls_colon and ls_comma into switch statement
Showing
1 changed file
with
14 additions
and
17 deletions
libqpdf/JSON.cc
| @@ -1156,7 +1156,9 @@ JSONParser::handleToken() | @@ -1156,7 +1156,9 @@ JSONParser::handleToken() | ||
| 1156 | "JSON: offset " + std::to_string(offset) + | 1156 | "JSON: offset " + std::to_string(offset) + |
| 1157 | ": unexpected colon"); | 1157 | ": unexpected colon"); |
| 1158 | } | 1158 | } |
| 1159 | - break; | 1159 | + parser_state = ps_dict_after_colon; |
| 1160 | + lex_state = ls_top; | ||
| 1161 | + return; | ||
| 1160 | 1162 | ||
| 1161 | case ls_comma: | 1163 | case ls_comma: |
| 1162 | if (!((parser_state == ps_dict_after_item) || | 1164 | if (!((parser_state == ps_dict_after_item) || |
| @@ -1166,7 +1168,16 @@ JSONParser::handleToken() | @@ -1166,7 +1168,16 @@ JSONParser::handleToken() | ||
| 1166 | "JSON: offset " + std::to_string(offset) + | 1168 | "JSON: offset " + std::to_string(offset) + |
| 1167 | ": unexpected comma"); | 1169 | ": unexpected comma"); |
| 1168 | } | 1170 | } |
| 1169 | - break; | 1171 | + if (parser_state == ps_dict_after_item) { |
| 1172 | + parser_state = ps_dict_after_comma; | ||
| 1173 | + } else if (parser_state == ps_array_after_item) { | ||
| 1174 | + parser_state = ps_array_after_comma; | ||
| 1175 | + } else { | ||
| 1176 | + throw std::logic_error("JSONParser::handleToken: unexpected parser" | ||
| 1177 | + " state for comma"); | ||
| 1178 | + } | ||
| 1179 | + lex_state = ls_top; | ||
| 1180 | + return; | ||
| 1170 | 1181 | ||
| 1171 | case ls_end_array: | 1182 | case ls_end_array: |
| 1172 | if (!((parser_state == ps_array_begin) || | 1183 | if (!((parser_state == ps_array_begin) || |
| @@ -1275,18 +1286,7 @@ JSONParser::handleToken() | @@ -1275,18 +1286,7 @@ JSONParser::handleToken() | ||
| 1275 | // whatever we need to do with it. | 1286 | // whatever we need to do with it. |
| 1276 | 1287 | ||
| 1277 | parser_state_e next_state = ps_top; | 1288 | parser_state_e next_state = ps_top; |
| 1278 | - if (lex_state == ls_colon) { | ||
| 1279 | - next_state = ps_dict_after_colon; | ||
| 1280 | - } else if (lex_state == ls_comma) { | ||
| 1281 | - if (parser_state == ps_dict_after_item) { | ||
| 1282 | - next_state = ps_dict_after_comma; | ||
| 1283 | - } else if (parser_state == ps_array_after_item) { | ||
| 1284 | - next_state = ps_array_after_comma; | ||
| 1285 | - } else { | ||
| 1286 | - throw std::logic_error("JSONParser::handleToken: unexpected parser" | ||
| 1287 | - " state for comma"); | ||
| 1288 | - } | ||
| 1289 | - } else if ((lex_state == ls_end_array) || (lex_state == ls_end_dict)) { | 1289 | + if ((lex_state == ls_end_array) || (lex_state == ls_end_dict)) { |
| 1290 | next_state = ps_stack.back(); | 1290 | next_state = ps_stack.back(); |
| 1291 | ps_stack.pop_back(); | 1291 | ps_stack.pop_back(); |
| 1292 | auto tos = stack.back(); | 1292 | auto tos = stack.back(); |
| @@ -1348,9 +1348,6 @@ JSONParser::handleToken() | @@ -1348,9 +1348,6 @@ JSONParser::handleToken() | ||
| 1348 | throw std::logic_error( | 1348 | throw std::logic_error( |
| 1349 | "JSONParser::handleToken: unexpected parser state"); | 1349 | "JSONParser::handleToken: unexpected parser state"); |
| 1350 | } | 1350 | } |
| 1351 | - } else { | ||
| 1352 | - throw std::logic_error( | ||
| 1353 | - "JSONParser::handleToken: unexpected null item in transition"); | ||
| 1354 | } | 1351 | } |
| 1355 | 1352 | ||
| 1356 | if (reactor && item.get()) { | 1353 | if (reactor && item.get()) { |