Commit 0de032bcdd49d50df6a3e4a2e6325e5144c4619e
1 parent
77ceebd6
In JSONParser::handleToken simplify setting of start and end
Showing
5 changed files
with
16 additions
and
20 deletions
libqpdf/JSON.cc
| @@ -1142,12 +1142,10 @@ JSONParser::handleToken() | @@ -1142,12 +1142,10 @@ JSONParser::handleToken() | ||
| 1142 | switch (lex_state) { | 1142 | switch (lex_state) { |
| 1143 | case ls_begin_dict: | 1143 | case ls_begin_dict: |
| 1144 | item = std::make_shared<JSON>(JSON::makeDictionary()); | 1144 | item = std::make_shared<JSON>(JSON::makeDictionary()); |
| 1145 | - item->setStart(token_start); | ||
| 1146 | break; | 1145 | break; |
| 1147 | 1146 | ||
| 1148 | case ls_begin_array: | 1147 | case ls_begin_array: |
| 1149 | item = std::make_shared<JSON>(JSON::makeArray()); | 1148 | item = std::make_shared<JSON>(JSON::makeArray()); |
| 1150 | - item->setStart(token_start); | ||
| 1151 | break; | 1149 | break; |
| 1152 | 1150 | ||
| 1153 | case ls_colon: | 1151 | case ls_colon: |
| @@ -1306,10 +1304,8 @@ JSONParser::handleToken() | @@ -1306,10 +1304,8 @@ JSONParser::handleToken() | ||
| 1306 | 1304 | ||
| 1307 | parser_state_e next_state = ps_top; | 1305 | parser_state_e next_state = ps_top; |
| 1308 | 1306 | ||
| 1309 | - if (!(item->isArray() || item->isDictionary())) { | ||
| 1310 | - item->setStart(token_start); | ||
| 1311 | - item->setEnd(offset); | ||
| 1312 | - } | 1307 | + item->setStart(token_start); |
| 1308 | + item->setEnd(offset); | ||
| 1313 | 1309 | ||
| 1314 | switch (parser_state) { | 1310 | switch (parser_state) { |
| 1315 | case ps_dict_begin: | 1311 | case ps_dict_begin: |
libtests/qtest/json_parse/good-01-react.out
| 1 | dictionary start | 1 | dictionary start |
| 2 | dictionary item: a -> [6, 11): "bcd" | 2 | dictionary item: a -> [6, 11): "bcd" |
| 3 | -dictionary item: e -> [18, 0): [] | 3 | +dictionary item: e -> [18, 19): [] |
| 4 | array start | 4 | array start |
| 5 | array item: [19, 20): 1 | 5 | array item: [19, 20): 1 |
| 6 | array item: [41, 42): 2 | 6 | array item: [41, 42): 2 |
| 7 | array item: [44, 45): 3 | 7 | array item: [44, 45): 3 |
| 8 | array item: [46, 47): 4 | 8 | array item: [46, 47): 4 |
| 9 | array item: [48, 54): "five" | 9 | array item: [48, 54): "five" |
| 10 | -array item: [56, 0): {} | 10 | +array item: [56, 57): {} |
| 11 | dictionary start | 11 | dictionary start |
| 12 | dictionary item: six -> [64, 65): 7 | 12 | dictionary item: six -> [64, 65): 7 |
| 13 | dictionary item: 8 -> [72, 73): 9 | 13 | dictionary item: 8 -> [72, 73): 9 |
libtests/qtest/json_parse/good-04-react.out
| 1 | array start | 1 | array start |
| 2 | -array item: [1, 0): [] | 2 | +array item: [1, 2): [] |
| 3 | array start | 3 | array start |
| 4 | -array item: [2, 0): [] | 4 | +array item: [2, 3): [] |
| 5 | array start | 5 | array start |
| 6 | -array item: [3, 0): {} | 6 | +array item: [3, 4): {} |
| 7 | dictionary start | 7 | dictionary start |
| 8 | container end: [3, 5): {} | 8 | container end: [3, 5): {} |
| 9 | container end: [2, 6): [] | 9 | container end: [2, 6): [] |
| 10 | -array item: [8, 0): {} | 10 | +array item: [8, 9): {} |
| 11 | dictionary start | 11 | dictionary start |
| 12 | -dictionary item: -> [13, 0): {} | 12 | +dictionary item: -> [13, 14): {} |
| 13 | dictionary start | 13 | dictionary start |
| 14 | container end: [13, 15): {} | 14 | container end: [13, 15): {} |
| 15 | container end: [8, 16): {} | 15 | container end: [8, 16): {} |
libtests/qtest/json_parse/good-10-react.out
| 1 | dictionary start | 1 | dictionary start |
| 2 | -dictionary item: a -> [9, 0): [] | 2 | +dictionary item: a -> [9, 10): [] |
| 3 | array start | 3 | array start |
| 4 | array item: [10, 11): 1 | 4 | array item: [10, 11): 1 |
| 5 | array item: [13, 14): 2 | 5 | array item: [13, 14): 2 |
| 6 | -array item: [16, 0): {} | 6 | +array item: [16, 17): {} |
| 7 | dictionary start | 7 | dictionary start |
| 8 | dictionary item: x -> [22, 25): "y" | 8 | dictionary item: x -> [22, 25): "y" |
| 9 | container end: [16, 26): {} | 9 | container end: [16, 26): {} |
| 10 | array item: [28, 29): 3 | 10 | array item: [28, 29): 3 |
| 11 | -array item: [31, 0): {} | 11 | +array item: [31, 32): {} |
| 12 | dictionary start | 12 | dictionary start |
| 13 | dictionary item: keep -> [40, 61): "not in final output" | 13 | dictionary item: keep -> [40, 61): "not in final output" |
| 14 | container end: [31, 62): { | 14 | container end: [31, 62): { |
| 15 | "keep": "not in final output" | 15 | "keep": "not in final output" |
| 16 | } | 16 | } |
| 17 | container end: [9, 63): [] | 17 | container end: [9, 63): [] |
| 18 | -dictionary item: keep -> [75, 0): [] | 18 | +dictionary item: keep -> [75, 76): [] |
| 19 | array start | 19 | array start |
| 20 | array item: [76, 77): 1 | 20 | array item: [76, 77): 1 |
| 21 | array item: [79, 83): null | 21 | array item: [79, 83): null |
| @@ -23,7 +23,7 @@ array item: [85, 86): 2 | @@ -23,7 +23,7 @@ array item: [85, 86): 2 | ||
| 23 | array item: [88, 93): false | 23 | array item: [88, 93): false |
| 24 | array item: [95, 101): "keep" | 24 | array item: [95, 101): "keep" |
| 25 | array item: [103, 104): 3 | 25 | array item: [103, 104): 3 |
| 26 | -array item: [106, 0): [] | 26 | +array item: [106, 107): [] |
| 27 | array start | 27 | array start |
| 28 | array item: [107, 113): "this" | 28 | array item: [107, 113): "this" |
| 29 | array item: [115, 121): "keep" | 29 | array item: [115, 121): "keep" |
libtests/qtest/json_parse/good-11-react.out
| 1 | array start | 1 | array start |
| 2 | -array item: [4, 0): [] | 2 | +array item: [4, 5): [] |
| 3 | array start | 3 | array start |
| 4 | array item: [5, 11): "u:π" | 4 | array item: [5, 11): "u:π" |
| 5 | array item: [13, 23): "u:π" | 5 | array item: [13, 23): "u:π" |
| 6 | array item: [25, 39): "b:EFBBBFCF80" | 6 | array item: [25, 39): "b:EFBBBFCF80" |
| 7 | array item: [41, 53): "b:feff03c0" | 7 | array item: [41, 53): "b:feff03c0" |
| 8 | container end: [4, 54): [] | 8 | container end: [4, 54): [] |
| 9 | -array item: [58, 0): [] | 9 | +array item: [58, 59): [] |
| 10 | array start | 10 | array start |
| 11 | array item: [59, 67): "u:🥔" | 11 | array item: [59, 67): "u:🥔" |
| 12 | array item: [69, 85): "u:🥔" | 12 | array item: [69, 85): "u:🥔" |