From 7de0b3f3c083990842523112959f8e27a0d2e5a0 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 9 Jan 2024 20:28:28 -0500 Subject: JSONHandler: add fallback handler support --- libqpdf/JSONHandler.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'libqpdf/JSONHandler.cc') diff --git a/libqpdf/JSONHandler.cc b/libqpdf/JSONHandler.cc index 4a69fd60..a8116cb0 100644 --- a/libqpdf/JSONHandler.cc +++ b/libqpdf/JSONHandler.cc @@ -17,10 +17,10 @@ struct Handlers JSONHandler::void_handler_t dict_end_handler{nullptr}; JSONHandler::json_handler_t array_start_handler{nullptr}; JSONHandler::void_handler_t array_end_handler{nullptr}; - JSONHandler::void_handler_t final_handler{nullptr}; std::map> dict_handlers; std::shared_ptr fallback_dict_handler; std::shared_ptr array_item_handler; + std::shared_ptr fallback_handler; }; class JSONHandler::Members @@ -110,6 +110,12 @@ JSONHandler::addArrayHandlers( m->h.array_item_handler = ah; } +void +JSONHandler::addFallbackHandler(std::shared_ptr h) +{ + m->h.fallback_handler = std::move(h); +} + void JSONHandler::handle(std::string const& path, JSON j) { @@ -169,6 +175,11 @@ JSONHandler::handle(std::string const& path, JSON j) return; } + if (m->h.fallback_handler) { + m->h.fallback_handler->handle(path, j); + return; + } + // It would be nice to include information about what type the object was and what types were // allowed, but we're relying on schema validation to make sure input is properly structured // before calling the handlers. It would be different if this code were trying to be part of a -- cgit v1.2.3-70-g09d2