Commit dab27c9bb35c26e30e22f2e53299ee9566cadefd
1 parent
fe74f28d
Refactor setting of object descriptions in QPDF::JSONReactor
Showing
4 changed files
with
34 additions
and
6 deletions
include/qpdf/QPDF.hh
| ... | ... | @@ -32,6 +32,7 @@ |
| 32 | 32 | #include <memory> |
| 33 | 33 | #include <stdio.h> |
| 34 | 34 | #include <string> |
| 35 | +#include <variant> | |
| 35 | 36 | #include <vector> |
| 36 | 37 | |
| 37 | 38 | #include <qpdf/Buffer.hh> |
| ... | ... | @@ -50,6 +51,7 @@ class BitStream; |
| 50 | 51 | class BitWriter; |
| 51 | 52 | class QPDFLogger; |
| 52 | 53 | class QPDFParser; |
| 54 | +struct JSON_Descr; | |
| 53 | 55 | |
| 54 | 56 | class QPDF |
| 55 | 57 | { |
| ... | ... | @@ -1152,6 +1154,7 @@ class QPDF |
| 1152 | 1154 | QPDF& pdf; |
| 1153 | 1155 | std::shared_ptr<InputSource> is; |
| 1154 | 1156 | bool must_be_complete; |
| 1157 | + std::shared_ptr<std::variant<std::string, JSON_Descr>> descr; | |
| 1155 | 1158 | bool errors; |
| 1156 | 1159 | bool parse_error; |
| 1157 | 1160 | bool saw_qpdf; | ... | ... |
libqpdf/QPDFValue.cc
| ... | ... | @@ -34,6 +34,14 @@ QPDFValue::getDescription() |
| 34 | 34 | } |
| 35 | 35 | return description; |
| 36 | 36 | } |
| 37 | + case 1: | |
| 38 | + { | |
| 39 | + auto j_descr = std::get<1>(*object_description); | |
| 40 | + return ( | |
| 41 | + *j_descr.input + | |
| 42 | + (j_descr.object.empty() ? "" : ", " + j_descr.object) + | |
| 43 | + " at offset " + std::to_string(parsed_offset)); | |
| 44 | + } | |
| 37 | 45 | } |
| 38 | 46 | } else if (og.isIndirect()) { |
| 39 | 47 | return "object " + og.unparse(' '); | ... | ... |
libqpdf/QPDF_json.cc
| ... | ... | @@ -4,6 +4,8 @@ |
| 4 | 4 | #include <qpdf/Pl_Base64.hh> |
| 5 | 5 | #include <qpdf/Pl_StdioFile.hh> |
| 6 | 6 | #include <qpdf/QIntC.hh> |
| 7 | +#include <qpdf/QPDFObject_private.hh> | |
| 8 | +#include <qpdf/QPDFValue.hh> | |
| 7 | 9 | #include <qpdf/QTC.hh> |
| 8 | 10 | #include <qpdf/QUtil.hh> |
| 9 | 11 | #include <algorithm> |
| ... | ... | @@ -226,6 +228,8 @@ QPDF::JSONReactor::JSONReactor( |
| 226 | 228 | pdf(pdf), |
| 227 | 229 | is(is), |
| 228 | 230 | must_be_complete(must_be_complete), |
| 231 | + descr(std::make_shared<std::variant<std::string, JSON_Descr>>( | |
| 232 | + JSON_Descr(std::make_shared<std::string>(is->getName()), ""))), | |
| 229 | 233 | errors(false), |
| 230 | 234 | parse_error(false), |
| 231 | 235 | saw_qpdf(false), |
| ... | ... | @@ -675,12 +679,13 @@ QPDF::JSONReactor::arrayItem(JSON const& value) |
| 675 | 679 | void |
| 676 | 680 | QPDF::JSONReactor::setObjectDescription(QPDFObjectHandle& oh, JSON const& value) |
| 677 | 681 | { |
| 678 | - std::string description = this->is->getName(); | |
| 679 | - if (!this->cur_object.empty()) { | |
| 680 | - description += ", " + this->cur_object; | |
| 682 | + auto j_descr = std::get<JSON_Descr>(*descr); | |
| 683 | + if (j_descr.object != cur_object) { | |
| 684 | + descr = std::make_shared<QPDFValue::Description>( | |
| 685 | + JSON_Descr(j_descr.input, cur_object)); | |
| 681 | 686 | } |
| 682 | - description += " at offset " + std::to_string(value.getStart()); | |
| 683 | - oh.setObjectDescription(&this->pdf, description); | |
| 687 | + | |
| 688 | + oh.getObjectPtr()->setDescription(&pdf, descr, value.getStart()); | |
| 684 | 689 | } |
| 685 | 690 | |
| 686 | 691 | QPDFObjectHandle | ... | ... |
libqpdf/qpdf/QPDFValue.hh
| ... | ... | @@ -14,6 +14,18 @@ class QPDF; |
| 14 | 14 | class QPDFObjectHandle; |
| 15 | 15 | class QPDFObject; |
| 16 | 16 | |
| 17 | +struct JSON_Descr | |
| 18 | +{ | |
| 19 | + JSON_Descr(std::shared_ptr<std::string> input, std::string const& object) : | |
| 20 | + input(input), | |
| 21 | + object(object) | |
| 22 | + { | |
| 23 | + } | |
| 24 | + | |
| 25 | + std::shared_ptr<std::string> input; | |
| 26 | + std::string object; | |
| 27 | +}; | |
| 28 | + | |
| 17 | 29 | class QPDFValue |
| 18 | 30 | { |
| 19 | 31 | friend class QPDFObject; |
| ... | ... | @@ -25,7 +37,7 @@ class QPDFValue |
| 25 | 37 | virtual std::string unparse() = 0; |
| 26 | 38 | virtual JSON getJSON(int json_version) = 0; |
| 27 | 39 | |
| 28 | - using Description = std::variant<std::string>; | |
| 40 | + using Description = std::variant<std::string, JSON_Descr>; | |
| 29 | 41 | |
| 30 | 42 | virtual void |
| 31 | 43 | setDescription( | ... | ... |