diff --git a/include/qpdf/ObjectHandle.hh b/include/qpdf/ObjectHandle.hh index 7eb0a64..83a5f4b 100644 --- a/include/qpdf/ObjectHandle.hh +++ b/include/qpdf/ObjectHandle.hh @@ -83,6 +83,7 @@ namespace qpdf QPDFObjectHandle operator[](size_t n) const; QPDFObjectHandle operator[](int n) const; + bool contains(std::string const& key) const; QPDFObjectHandle const& operator[](std::string const& key) const; std::shared_ptr copy(bool shallow = false) const; diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc index 659f676..4a7e4e7 100644 --- a/libqpdf/QPDF_Dictionary.cc +++ b/libqpdf/QPDF_Dictionary.cc @@ -30,10 +30,9 @@ BaseHandle::operator[](std::string const& key) const } bool -BaseDictionary::hasKey(std::string const& key) const +BaseHandle::contains(std::string const& key) const { - auto d = dict(); - return d->items.contains(key) && !d->items[key].null(); + return !(*this)[key].null(); } QPDFObjectHandle @@ -122,9 +121,8 @@ QPDFObjectHandle::checkOwnership(QPDFObjectHandle const& item) const bool QPDFObjectHandle::hasKey(std::string const& key) const { - auto dict = as_dictionary(strict); - if (dict) { - return dict.hasKey(key); + if (Dictionary dict = *this) { + return dict.contains(key); } else { typeWarning("dictionary", "returning false for a key containment request"); QTC::TC("qpdf", "QPDFObjectHandle dictionary false for hasKey"); diff --git a/libqpdf/qpdf/QPDFObjectHandle_private.hh b/libqpdf/qpdf/QPDFObjectHandle_private.hh index 0e6789e..4d2f972 100644 --- a/libqpdf/qpdf/QPDFObjectHandle_private.hh +++ b/libqpdf/qpdf/QPDFObjectHandle_private.hh @@ -120,7 +120,6 @@ namespace qpdf { public: // The following methods are not part of the public API. - bool hasKey(std::string const& key) const; QPDFObjectHandle getKey(std::string const& key) const; std::set getKeys(); std::map const& getAsMap() const;