From 0de032bcdd49d50df6a3e4a2e6325e5144c4619e Mon Sep 17 00:00:00 2001 From: m-holger Date: Fri, 27 Jan 2023 11:12:30 +0000 Subject: [PATCH] In JSONParser::handleToken simplify setting of start and end --- libqpdf/JSON.cc | 8 ++------ libtests/qtest/json_parse/good-01-react.out | 4 ++-- libtests/qtest/json_parse/good-04-react.out | 10 +++++----- libtests/qtest/json_parse/good-10-react.out | 10 +++++----- libtests/qtest/json_parse/good-11-react.out | 4 ++-- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc index 9775bc39..1749005b 100644 --- a/libqpdf/JSON.cc +++ b/libqpdf/JSON.cc @@ -1142,12 +1142,10 @@ JSONParser::handleToken() switch (lex_state) { case ls_begin_dict: item = std::make_shared(JSON::makeDictionary()); - item->setStart(token_start); break; case ls_begin_array: item = std::make_shared(JSON::makeArray()); - item->setStart(token_start); break; case ls_colon: @@ -1306,10 +1304,8 @@ JSONParser::handleToken() parser_state_e next_state = ps_top; - if (!(item->isArray() || item->isDictionary())) { - item->setStart(token_start); - item->setEnd(offset); - } + item->setStart(token_start); + item->setEnd(offset); switch (parser_state) { case ps_dict_begin: diff --git a/libtests/qtest/json_parse/good-01-react.out b/libtests/qtest/json_parse/good-01-react.out index e3813bcc..3951272d 100644 --- a/libtests/qtest/json_parse/good-01-react.out +++ b/libtests/qtest/json_parse/good-01-react.out @@ -1,13 +1,13 @@ dictionary start dictionary item: a -> [6, 11): "bcd" -dictionary item: e -> [18, 0): [] +dictionary item: e -> [18, 19): [] array start array item: [19, 20): 1 array item: [41, 42): 2 array item: [44, 45): 3 array item: [46, 47): 4 array item: [48, 54): "five" -array item: [56, 0): {} +array item: [56, 57): {} dictionary start dictionary item: six -> [64, 65): 7 dictionary item: 8 -> [72, 73): 9 diff --git a/libtests/qtest/json_parse/good-04-react.out b/libtests/qtest/json_parse/good-04-react.out index ded004b2..8d931535 100644 --- a/libtests/qtest/json_parse/good-04-react.out +++ b/libtests/qtest/json_parse/good-04-react.out @@ -1,15 +1,15 @@ array start -array item: [1, 0): [] +array item: [1, 2): [] array start -array item: [2, 0): [] +array item: [2, 3): [] array start -array item: [3, 0): {} +array item: [3, 4): {} dictionary start container end: [3, 5): {} container end: [2, 6): [] -array item: [8, 0): {} +array item: [8, 9): {} dictionary start -dictionary item: -> [13, 0): {} +dictionary item: -> [13, 14): {} dictionary start container end: [13, 15): {} container end: [8, 16): {} diff --git a/libtests/qtest/json_parse/good-10-react.out b/libtests/qtest/json_parse/good-10-react.out index 3cceeb2f..8c31f915 100644 --- a/libtests/qtest/json_parse/good-10-react.out +++ b/libtests/qtest/json_parse/good-10-react.out @@ -1,21 +1,21 @@ dictionary start -dictionary item: a -> [9, 0): [] +dictionary item: a -> [9, 10): [] array start array item: [10, 11): 1 array item: [13, 14): 2 -array item: [16, 0): {} +array item: [16, 17): {} dictionary start dictionary item: x -> [22, 25): "y" container end: [16, 26): {} array item: [28, 29): 3 -array item: [31, 0): {} +array item: [31, 32): {} dictionary start dictionary item: keep -> [40, 61): "not in final output" container end: [31, 62): { "keep": "not in final output" } container end: [9, 63): [] -dictionary item: keep -> [75, 0): [] +dictionary item: keep -> [75, 76): [] array start array item: [76, 77): 1 array item: [79, 83): null @@ -23,7 +23,7 @@ array item: [85, 86): 2 array item: [88, 93): false array item: [95, 101): "keep" array item: [103, 104): 3 -array item: [106, 0): [] +array item: [106, 107): [] array start array item: [107, 113): "this" array item: [115, 121): "keep" diff --git a/libtests/qtest/json_parse/good-11-react.out b/libtests/qtest/json_parse/good-11-react.out index 6cf3345e..6d7d4275 100644 --- a/libtests/qtest/json_parse/good-11-react.out +++ b/libtests/qtest/json_parse/good-11-react.out @@ -1,12 +1,12 @@ array start -array item: [4, 0): [] +array item: [4, 5): [] array start array item: [5, 11): "u:π" array item: [13, 23): "u:π" array item: [25, 39): "b:EFBBBFCF80" array item: [41, 53): "b:feff03c0" container end: [4, 54): [] -array item: [58, 0): [] +array item: [58, 59): [] array start array item: [59, 67): "u:🥔" array item: [69, 85): "u:🥔"