diff options
author | Jay Berkenbilt <jberkenbilt@users.noreply.github.com> | 2023-02-18 23:49:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-18 23:49:18 +0100 |
commit | b3cfa1010f95514a13590266dd50677445f74309 (patch) | |
tree | 68ff8d71c63d27d59d05b1b0d8ed503319463a91 /libqpdf/QPDFValue.cc | |
parent | e4e03e9ac10d8ea0c1a8ef8c78f0103068928822 (diff) | |
parent | 07bb5c3dd6213af9c9a64e17ae2d457cf4fc7190 (diff) | |
download | qpdf-b3cfa1010f95514a13590266dd50677445f74309.tar.zst |
Merge pull request #902 from m-holger/od
Refactor creation of object descriptions
Diffstat (limited to 'libqpdf/QPDFValue.cc')
-rw-r--r-- | libqpdf/QPDFValue.cc | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/libqpdf/QPDFValue.cc b/libqpdf/QPDFValue.cc index ca3205b7..30d534dc 100644 --- a/libqpdf/QPDFValue.cc +++ b/libqpdf/QPDFValue.cc @@ -9,3 +9,58 @@ QPDFValue::do_create(QPDFValue* object) obj->value = std::shared_ptr<QPDFValue>(object); return obj; } + +std::string +QPDFValue::getDescription() +{ + if (object_description) { + switch (object_description->index()) { + case 0: + { + // Simple template string + auto description = std::get<0>(*object_description); + + if (auto pos = description.find("$OG"); + pos != std::string::npos) { + description.replace(pos, 3, og.unparse(' ')); + } + if (auto pos = description.find("$PO"); + pos != std::string::npos) { + qpdf_offset_t shift = (type_code == ::ot_dictionary) ? 2 + : (type_code == ::ot_array) ? 1 + : 0; + + description.replace( + pos, 3, std::to_string(parsed_offset + shift)); + } + return description; + } + case 1: + { + // QPDF::JSONReactor generated description + 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)); + } + case 2: + { + // Child object description + auto j_descr = std::get<2>(*object_description); + std::string result; + if (auto p = j_descr.parent.lock()) { + result = p->getDescription(); + } + result += j_descr.static_descr; + if (auto pos = result.find("$VD"); pos != std::string::npos) { + result.replace(pos, 3, j_descr.var_descr); + } + return result; + } + } + } else if (og.isIndirect()) { + return "object " + og.unparse(' '); + } + return {}; +} |