diff options
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QPDFValue.cc | 8 | ||||
-rw-r--r-- | libqpdf/QPDF_json.cc | 15 | ||||
-rw-r--r-- | libqpdf/qpdf/QPDFValue.hh | 14 |
3 files changed, 31 insertions, 6 deletions
diff --git a/libqpdf/QPDFValue.cc b/libqpdf/QPDFValue.cc index 41a00fa8..a89afd55 100644 --- a/libqpdf/QPDFValue.cc +++ b/libqpdf/QPDFValue.cc @@ -34,6 +34,14 @@ QPDFValue::getDescription() } return description; } + case 1: + { + auto j_descr = std::get<1>(*object_description); + return ( + *j_descr.input + + (j_descr.object.empty() ? "" : ", " + j_descr.object) + + " at offset " + std::to_string(parsed_offset)); + } } } else if (og.isIndirect()) { return "object " + og.unparse(' '); diff --git a/libqpdf/QPDF_json.cc b/libqpdf/QPDF_json.cc index 02dc57e8..fb858557 100644 --- a/libqpdf/QPDF_json.cc +++ b/libqpdf/QPDF_json.cc @@ -4,6 +4,8 @@ #include <qpdf/Pl_Base64.hh> #include <qpdf/Pl_StdioFile.hh> #include <qpdf/QIntC.hh> +#include <qpdf/QPDFObject_private.hh> +#include <qpdf/QPDFValue.hh> #include <qpdf/QTC.hh> #include <qpdf/QUtil.hh> #include <algorithm> @@ -226,6 +228,8 @@ QPDF::JSONReactor::JSONReactor( pdf(pdf), is(is), must_be_complete(must_be_complete), + descr(std::make_shared<std::variant<std::string, JSON_Descr>>( + JSON_Descr(std::make_shared<std::string>(is->getName()), ""))), errors(false), parse_error(false), saw_qpdf(false), @@ -675,12 +679,13 @@ QPDF::JSONReactor::arrayItem(JSON const& value) void QPDF::JSONReactor::setObjectDescription(QPDFObjectHandle& oh, JSON const& value) { - std::string description = this->is->getName(); - if (!this->cur_object.empty()) { - description += ", " + this->cur_object; + auto j_descr = std::get<JSON_Descr>(*descr); + if (j_descr.object != cur_object) { + descr = std::make_shared<QPDFValue::Description>( + JSON_Descr(j_descr.input, cur_object)); } - description += " at offset " + std::to_string(value.getStart()); - oh.setObjectDescription(&this->pdf, description); + + oh.getObjectPtr()->setDescription(&pdf, descr, value.getStart()); } QPDFObjectHandle diff --git a/libqpdf/qpdf/QPDFValue.hh b/libqpdf/qpdf/QPDFValue.hh index 8e9d4ea5..2e0c5e8d 100644 --- a/libqpdf/qpdf/QPDFValue.hh +++ b/libqpdf/qpdf/QPDFValue.hh @@ -14,6 +14,18 @@ class QPDF; class QPDFObjectHandle; class QPDFObject; +struct JSON_Descr +{ + JSON_Descr(std::shared_ptr<std::string> input, std::string const& object) : + input(input), + object(object) + { + } + + std::shared_ptr<std::string> input; + std::string object; +}; + class QPDFValue { friend class QPDFObject; @@ -25,7 +37,7 @@ class QPDFValue virtual std::string unparse() = 0; virtual JSON getJSON(int json_version) = 0; - using Description = std::variant<std::string>; + using Description = std::variant<std::string, JSON_Descr>; virtual void setDescription( |