mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-03 07:12:28 +00:00
JSONHandler: pass JSON object to dict start function
If some keys depend on others, we have to check up front since there is no control of what order key handlers will be called. Anyway, keys are unordered in json, so we don't want to depend on ordering.
This commit is contained in:
parent
11a86e444d
commit
ce3406e93f
@ -49,7 +49,7 @@ JSONHandler::addBoolHandler(bool_handler_t fn)
|
||||
}
|
||||
|
||||
void
|
||||
JSONHandler::addDictHandlers(void_handler_t start_fn, void_handler_t end_fn)
|
||||
JSONHandler::addDictHandlers(json_handler_t start_fn, void_handler_t end_fn)
|
||||
{
|
||||
this->m->h.dict_start_handler = start_fn;
|
||||
this->m->h.dict_end_handler = end_fn;
|
||||
@ -111,7 +111,7 @@ JSONHandler::handle(std::string const& path, JSON j)
|
||||
}
|
||||
if (this->m->h.dict_start_handler && j.isDictionary())
|
||||
{
|
||||
this->m->h.dict_start_handler(path);
|
||||
this->m->h.dict_start_handler(path, j);
|
||||
std::string path_base = path;
|
||||
if (path_base != ".")
|
||||
{
|
||||
|
@ -58,7 +58,7 @@ class JSONHandler
|
||||
void addBoolHandler(bool_handler_t fn);
|
||||
|
||||
QPDF_DLL
|
||||
void addDictHandlers(void_handler_t start_fn, void_handler_t end_fn);
|
||||
void addDictHandlers(json_handler_t start_fn, void_handler_t end_fn);
|
||||
QPDF_DLL
|
||||
void addDictKeyHandler(
|
||||
std::string const& key, std::shared_ptr<JSONHandler>);
|
||||
@ -100,7 +100,7 @@ class JSONHandler
|
||||
string_handler_t string_handler;
|
||||
string_handler_t number_handler;
|
||||
bool_handler_t bool_handler;
|
||||
void_handler_t dict_start_handler;
|
||||
json_handler_t dict_start_handler;
|
||||
void_handler_t dict_end_handler;
|
||||
void_handler_t array_start_handler;
|
||||
void_handler_t array_end_handler;
|
||||
|
@ -49,8 +49,7 @@ static std::shared_ptr<JSONHandler> make_all_handler()
|
||||
{
|
||||
auto h = std::make_shared<JSONHandler>();
|
||||
h->addDictHandlers(
|
||||
make_print_message("dict begin"),
|
||||
make_print_message("dict end"));
|
||||
print_json, make_print_message("dict end"));
|
||||
auto h1 = std::make_shared<JSONHandler>();
|
||||
h1->addStringHandler(print_string);
|
||||
h->addDictKeyHandler("one", h1);
|
||||
@ -77,13 +76,11 @@ static std::shared_ptr<JSONHandler> make_all_handler()
|
||||
h5);
|
||||
auto h6 = std::make_shared<JSONHandler>();
|
||||
h6->addDictHandlers(
|
||||
make_print_message("dict begin"),
|
||||
make_print_message("dict end"));
|
||||
print_json, make_print_message("dict end"));
|
||||
auto h6a = std::make_shared<JSONHandler>();
|
||||
h6->addDictKeyHandler("a", h6a);
|
||||
h6a->addDictHandlers(
|
||||
make_print_message("dict begin"),
|
||||
make_print_message("dict end"));
|
||||
print_json, make_print_message("dict end"));
|
||||
auto h6ab = std::make_shared<JSONHandler>();
|
||||
h6a->addDictKeyHandler("b", h6ab);
|
||||
auto h6ax = std::make_shared<JSONHandler>();
|
||||
|
@ -1,7 +1,30 @@
|
||||
-- scalar --
|
||||
.: string: potato
|
||||
-- all --
|
||||
.: json: dict begin
|
||||
.: json: {
|
||||
"five": [
|
||||
"x",
|
||||
false,
|
||||
"y",
|
||||
null,
|
||||
true
|
||||
],
|
||||
"four": [
|
||||
"a",
|
||||
1
|
||||
],
|
||||
"one": "potato",
|
||||
"phour": null,
|
||||
"six": {
|
||||
"a": {
|
||||
"Q": "baaa",
|
||||
"b": "quack"
|
||||
},
|
||||
"b": "moo"
|
||||
},
|
||||
"three": true,
|
||||
"two": 3.14
|
||||
}
|
||||
.five: json: array begin
|
||||
.five[0]: string: x
|
||||
.five[1]: bool: false
|
||||
@ -15,8 +38,17 @@
|
||||
]
|
||||
.one: string: potato
|
||||
.phour: json: null
|
||||
.six: json: dict begin
|
||||
.six.a: json: dict begin
|
||||
.six: json: {
|
||||
"a": {
|
||||
"Q": "baaa",
|
||||
"b": "quack"
|
||||
},
|
||||
"b": "moo"
|
||||
}
|
||||
.six.a: json: {
|
||||
"Q": "baaa",
|
||||
"b": "quack"
|
||||
}
|
||||
.six.a.Q: json: "baaa"
|
||||
.six.a.b: string: quack
|
||||
.six.a: json: dict end
|
||||
@ -27,5 +59,7 @@
|
||||
.: json: dict end
|
||||
-- errors --
|
||||
bad type at top: JSON handler: value at . is not of expected type
|
||||
.: json: dict begin
|
||||
.: json: {
|
||||
"x": "y"
|
||||
}
|
||||
unexpected key: JSON handler found unexpected key x in object at .
|
||||
|
Loading…
Reference in New Issue
Block a user