aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2023-02-09 13:43:56 +0100
committerm-holger <m-holger@kubitscheck.org>2023-02-18 09:33:08 +0100
commitdab27c9bb35c26e30e22f2e53299ee9566cadefd (patch)
treed9a0c711329c495442c26e0ca2697847cdf2feeb
parentfe74f28dc4f269e4bf944ae61d77874f81f95daf (diff)
downloadqpdf-dab27c9bb35c26e30e22f2e53299ee9566cadefd.tar.zst
Refactor setting of object descriptions in QPDF::JSONReactor
-rw-r--r--include/qpdf/QPDF.hh3
-rw-r--r--libqpdf/QPDFValue.cc8
-rw-r--r--libqpdf/QPDF_json.cc15
-rw-r--r--libqpdf/qpdf/QPDFValue.hh14
4 files changed, 34 insertions, 6 deletions
diff --git a/include/qpdf/QPDF.hh b/include/qpdf/QPDF.hh
index d6b32fe9..b227bb37 100644
--- a/include/qpdf/QPDF.hh
+++ b/include/qpdf/QPDF.hh
@@ -32,6 +32,7 @@
#include <memory>
#include <stdio.h>
#include <string>
+#include <variant>
#include <vector>
#include <qpdf/Buffer.hh>
@@ -50,6 +51,7 @@ class BitStream;
class BitWriter;
class QPDFLogger;
class QPDFParser;
+struct JSON_Descr;
class QPDF
{
@@ -1152,6 +1154,7 @@ class QPDF
QPDF& pdf;
std::shared_ptr<InputSource> is;
bool must_be_complete;
+ std::shared_ptr<std::variant<std::string, JSON_Descr>> descr;
bool errors;
bool parse_error;
bool saw_qpdf;
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(