Commit 07bb5c3dd6213af9c9a64e17ae2d457cf4fc7190
1 parent
1496472e
Overload QPDF_Null::create to take a child object description
Showing
4 changed files
with
39 additions
and
15 deletions
libqpdf/QPDFObjectHandle.cc
| @@ -802,12 +802,10 @@ QPDFObjectHandle::getArrayNItems() | @@ -802,12 +802,10 @@ QPDFObjectHandle::getArrayNItems() | ||
| 802 | QPDFObjectHandle | 802 | QPDFObjectHandle |
| 803 | QPDFObjectHandle::getArrayItem(int n) | 803 | QPDFObjectHandle::getArrayItem(int n) |
| 804 | { | 804 | { |
| 805 | - QPDFObjectHandle result; | ||
| 806 | auto array = asArray(); | 805 | auto array = asArray(); |
| 807 | if (array && (n < array->getNItems()) && (n >= 0)) { | 806 | if (array && (n < array->getNItems()) && (n >= 0)) { |
| 808 | - result = array->getItem(n); | 807 | + return array->getItem(n); |
| 809 | } else { | 808 | } else { |
| 810 | - result = newNull(); | ||
| 811 | if (array) { | 809 | if (array) { |
| 812 | objectWarning("returning null for out of bounds array access"); | 810 | objectWarning("returning null for out of bounds array access"); |
| 813 | QTC::TC("qpdf", "QPDFObjectHandle array bounds"); | 811 | QTC::TC("qpdf", "QPDFObjectHandle array bounds"); |
| @@ -817,9 +815,8 @@ QPDFObjectHandle::getArrayItem(int n) | @@ -817,9 +815,8 @@ QPDFObjectHandle::getArrayItem(int n) | ||
| 817 | } | 815 | } |
| 818 | static auto constexpr msg = | 816 | static auto constexpr msg = |
| 819 | " -> null returned from invalid array access"sv; | 817 | " -> null returned from invalid array access"sv; |
| 820 | - result.obj->setChildDescription(obj, msg, ""); | 818 | + return QPDF_Null::create(obj, msg, ""); |
| 821 | } | 819 | } |
| 822 | - return result; | ||
| 823 | } | 820 | } |
| 824 | 821 | ||
| 825 | bool | 822 | bool |
| @@ -1028,19 +1025,15 @@ QPDFObjectHandle::hasKey(std::string const& key) | @@ -1028,19 +1025,15 @@ QPDFObjectHandle::hasKey(std::string const& key) | ||
| 1028 | QPDFObjectHandle | 1025 | QPDFObjectHandle |
| 1029 | QPDFObjectHandle::getKey(std::string const& key) | 1026 | QPDFObjectHandle::getKey(std::string const& key) |
| 1030 | { | 1027 | { |
| 1031 | - QPDFObjectHandle result; | ||
| 1032 | - auto dict = asDictionary(); | ||
| 1033 | - if (dict) { | ||
| 1034 | - result = dict->getKey(key); | 1028 | + if (auto dict = asDictionary()) { |
| 1029 | + return dict->getKey(key); | ||
| 1035 | } else { | 1030 | } else { |
| 1036 | typeWarning("dictionary", "returning null for attempted key retrieval"); | 1031 | typeWarning("dictionary", "returning null for attempted key retrieval"); |
| 1037 | QTC::TC("qpdf", "QPDFObjectHandle dictionary null for getKey"); | 1032 | QTC::TC("qpdf", "QPDFObjectHandle dictionary null for getKey"); |
| 1038 | - result = newNull(); | ||
| 1039 | static auto constexpr msg = | 1033 | static auto constexpr msg = |
| 1040 | " -> null returned from getting key $VD from non-Dictionary"sv; | 1034 | " -> null returned from getting key $VD from non-Dictionary"sv; |
| 1041 | - result.obj->setChildDescription(obj, msg, key); | 1035 | + return QPDF_Null::create(obj, msg, ""); |
| 1042 | } | 1036 | } |
| 1043 | - return result; | ||
| 1044 | } | 1037 | } |
| 1045 | 1038 | ||
| 1046 | QPDFObjectHandle | 1039 | QPDFObjectHandle |
libqpdf/QPDF_Dictionary.cc
| @@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
| 2 | 2 | ||
| 3 | #include <qpdf/QPDFObject_private.hh> | 3 | #include <qpdf/QPDFObject_private.hh> |
| 4 | #include <qpdf/QPDF_Name.hh> | 4 | #include <qpdf/QPDF_Name.hh> |
| 5 | +#include <qpdf/QPDF_Null.hh> | ||
| 5 | 6 | ||
| 6 | using namespace std::literals; | 7 | using namespace std::literals; |
| 7 | 8 | ||
| @@ -100,10 +101,8 @@ QPDF_Dictionary::getKey(std::string const& key) | @@ -100,10 +101,8 @@ QPDF_Dictionary::getKey(std::string const& key) | ||
| 100 | // May be a null object | 101 | // May be a null object |
| 101 | return item->second; | 102 | return item->second; |
| 102 | } else { | 103 | } else { |
| 103 | - auto null = QPDFObjectHandle::newNull(); | ||
| 104 | static auto constexpr msg = " -> dictionary key $VD"sv; | 104 | static auto constexpr msg = " -> dictionary key $VD"sv; |
| 105 | - null.getObj()->setChildDescription(shared_from_this(), msg, key); | ||
| 106 | - return null; | 105 | + return QPDF_Null::create(shared_from_this(), msg, key); |
| 107 | } | 106 | } |
| 108 | } | 107 | } |
| 109 | 108 |
libqpdf/QPDF_Null.cc
| 1 | #include <qpdf/QPDF_Null.hh> | 1 | #include <qpdf/QPDF_Null.hh> |
| 2 | 2 | ||
| 3 | +#include <qpdf/QPDFObject_private.hh> | ||
| 4 | + | ||
| 3 | QPDF_Null::QPDF_Null() : | 5 | QPDF_Null::QPDF_Null() : |
| 4 | QPDFValue(::ot_null, "null") | 6 | QPDFValue(::ot_null, "null") |
| 5 | { | 7 | { |
| @@ -12,6 +14,28 @@ QPDF_Null::create() | @@ -12,6 +14,28 @@ QPDF_Null::create() | ||
| 12 | } | 14 | } |
| 13 | 15 | ||
| 14 | std::shared_ptr<QPDFObject> | 16 | std::shared_ptr<QPDFObject> |
| 17 | +QPDF_Null::create( | ||
| 18 | + std::shared_ptr<QPDFObject> parent, | ||
| 19 | + std::string_view const& static_descr, | ||
| 20 | + std::string var_descr) | ||
| 21 | +{ | ||
| 22 | + auto n = do_create(new QPDF_Null()); | ||
| 23 | + n->setChildDescription(parent, static_descr, var_descr); | ||
| 24 | + return n; | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +std::shared_ptr<QPDFObject> | ||
| 28 | +QPDF_Null::create( | ||
| 29 | + std::shared_ptr<QPDFValue> parent, | ||
| 30 | + std::string_view const& static_descr, | ||
| 31 | + std::string var_descr) | ||
| 32 | +{ | ||
| 33 | + auto n = do_create(new QPDF_Null()); | ||
| 34 | + n->setChildDescription(parent, static_descr, var_descr); | ||
| 35 | + return n; | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +std::shared_ptr<QPDFObject> | ||
| 15 | QPDF_Null::copy(bool shallow) | 39 | QPDF_Null::copy(bool shallow) |
| 16 | { | 40 | { |
| 17 | return create(); | 41 | return create(); |
libqpdf/qpdf/QPDF_Null.hh
| @@ -8,6 +8,14 @@ class QPDF_Null: public QPDFValue | @@ -8,6 +8,14 @@ class QPDF_Null: public QPDFValue | ||
| 8 | public: | 8 | public: |
| 9 | virtual ~QPDF_Null() = default; | 9 | virtual ~QPDF_Null() = default; |
| 10 | static std::shared_ptr<QPDFObject> create(); | 10 | static std::shared_ptr<QPDFObject> create(); |
| 11 | + static std::shared_ptr<QPDFObject> create( | ||
| 12 | + std::shared_ptr<QPDFObject> parent, | ||
| 13 | + std::string_view const& static_descr, | ||
| 14 | + std::string var_descr); | ||
| 15 | + static std::shared_ptr<QPDFObject> create( | ||
| 16 | + std::shared_ptr<QPDFValue> parent, | ||
| 17 | + std::string_view const& static_descr, | ||
| 18 | + std::string var_descr); | ||
| 11 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); | 19 | virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); |
| 12 | virtual std::string unparse(); | 20 | virtual std::string unparse(); |
| 13 | virtual JSON getJSON(int json_version); | 21 | virtual JSON getJSON(int json_version); |