diff options
-rw-r--r-- | libqpdf/QPDFObjectHandle.cc | 17 | ||||
-rw-r--r-- | libqpdf/QPDF_Dictionary.cc | 5 | ||||
-rw-r--r-- | libqpdf/QPDF_Null.cc | 24 | ||||
-rw-r--r-- | libqpdf/qpdf/QPDF_Null.hh | 8 |
4 files changed, 39 insertions, 15 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index cbe42995..d474dcce 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -802,12 +802,10 @@ QPDFObjectHandle::getArrayNItems() QPDFObjectHandle QPDFObjectHandle::getArrayItem(int n) { - QPDFObjectHandle result; auto array = asArray(); if (array && (n < array->getNItems()) && (n >= 0)) { - result = array->getItem(n); + return array->getItem(n); } else { - result = newNull(); if (array) { objectWarning("returning null for out of bounds array access"); QTC::TC("qpdf", "QPDFObjectHandle array bounds"); @@ -817,9 +815,8 @@ QPDFObjectHandle::getArrayItem(int n) } static auto constexpr msg = " -> null returned from invalid array access"sv; - result.obj->setChildDescription(obj, msg, ""); + return QPDF_Null::create(obj, msg, ""); } - return result; } bool @@ -1028,19 +1025,15 @@ QPDFObjectHandle::hasKey(std::string const& key) QPDFObjectHandle QPDFObjectHandle::getKey(std::string const& key) { - QPDFObjectHandle result; - auto dict = asDictionary(); - if (dict) { - result = dict->getKey(key); + if (auto dict = asDictionary()) { + return dict->getKey(key); } else { typeWarning("dictionary", "returning null for attempted key retrieval"); QTC::TC("qpdf", "QPDFObjectHandle dictionary null for getKey"); - result = newNull(); static auto constexpr msg = " -> null returned from getting key $VD from non-Dictionary"sv; - result.obj->setChildDescription(obj, msg, key); + return QPDF_Null::create(obj, msg, ""); } - return result; } QPDFObjectHandle diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc index f45c00c6..43ad8a85 100644 --- a/libqpdf/QPDF_Dictionary.cc +++ b/libqpdf/QPDF_Dictionary.cc @@ -2,6 +2,7 @@ #include <qpdf/QPDFObject_private.hh> #include <qpdf/QPDF_Name.hh> +#include <qpdf/QPDF_Null.hh> using namespace std::literals; @@ -100,10 +101,8 @@ QPDF_Dictionary::getKey(std::string const& key) // May be a null object return item->second; } else { - auto null = QPDFObjectHandle::newNull(); static auto constexpr msg = " -> dictionary key $VD"sv; - null.getObj()->setChildDescription(shared_from_this(), msg, key); - return null; + return QPDF_Null::create(shared_from_this(), msg, key); } } diff --git a/libqpdf/QPDF_Null.cc b/libqpdf/QPDF_Null.cc index 6ec4556c..a82f23c0 100644 --- a/libqpdf/QPDF_Null.cc +++ b/libqpdf/QPDF_Null.cc @@ -1,5 +1,7 @@ #include <qpdf/QPDF_Null.hh> +#include <qpdf/QPDFObject_private.hh> + QPDF_Null::QPDF_Null() : QPDFValue(::ot_null, "null") { @@ -12,6 +14,28 @@ QPDF_Null::create() } std::shared_ptr<QPDFObject> +QPDF_Null::create( + std::shared_ptr<QPDFObject> parent, + std::string_view const& static_descr, + std::string var_descr) +{ + auto n = do_create(new QPDF_Null()); + n->setChildDescription(parent, static_descr, var_descr); + return n; +} + +std::shared_ptr<QPDFObject> +QPDF_Null::create( + std::shared_ptr<QPDFValue> parent, + std::string_view const& static_descr, + std::string var_descr) +{ + auto n = do_create(new QPDF_Null()); + n->setChildDescription(parent, static_descr, var_descr); + return n; +} + +std::shared_ptr<QPDFObject> QPDF_Null::copy(bool shallow) { return create(); diff --git a/libqpdf/qpdf/QPDF_Null.hh b/libqpdf/qpdf/QPDF_Null.hh index 1a92b214..2bbb3db5 100644 --- a/libqpdf/qpdf/QPDF_Null.hh +++ b/libqpdf/qpdf/QPDF_Null.hh @@ -8,6 +8,14 @@ class QPDF_Null: public QPDFValue public: virtual ~QPDF_Null() = default; static std::shared_ptr<QPDFObject> create(); + static std::shared_ptr<QPDFObject> create( + std::shared_ptr<QPDFObject> parent, + std::string_view const& static_descr, + std::string var_descr); + static std::shared_ptr<QPDFObject> create( + std::shared_ptr<QPDFValue> parent, + std::string_view const& static_descr, + std::string var_descr); virtual std::shared_ptr<QPDFObject> copy(bool shallow = false); virtual std::string unparse(); virtual JSON getJSON(int json_version); |