mirror of
https://github.com/qpdf/qpdf.git
synced 2024-06-01 01:40:51 +00:00
Refactor setting of object descriptions in QPDF::JSONReactor
This commit is contained in:
parent
fe74f28dc4
commit
dab27c9bb3
|
@ -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;
|
||||
|
|
|
@ -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(' ');
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue
Block a user