Commit 08dcf84c2c8cb04e795b7735fdb594e7487cdee3

Authored by m-holger
1 parent cbeaf5a8

Replace `hasKey` with `contains` in `BaseDictionary` and `QPDFObjectHandle`, ref…

…actor implementation to simplify null handling and align with API conventions.
include/qpdf/ObjectHandle.hh
... ... @@ -83,6 +83,7 @@ namespace qpdf
83 83 QPDFObjectHandle operator[](size_t n) const;
84 84 QPDFObjectHandle operator[](int n) const;
85 85  
  86 + bool contains(std::string const& key) const;
86 87 QPDFObjectHandle const& operator[](std::string const& key) const;
87 88  
88 89 std::shared_ptr<QPDFObject> copy(bool shallow = false) const;
... ...
libqpdf/QPDF_Dictionary.cc
... ... @@ -30,10 +30,9 @@ BaseHandle::operator[](std::string const&amp; key) const
30 30 }
31 31  
32 32 bool
33   -BaseDictionary::hasKey(std::string const& key) const
  33 +BaseHandle::contains(std::string const& key) const
34 34 {
35   - auto d = dict();
36   - return d->items.contains(key) && !d->items[key].null();
  35 + return !(*this)[key].null();
37 36 }
38 37  
39 38 QPDFObjectHandle
... ... @@ -122,9 +121,8 @@ QPDFObjectHandle::checkOwnership(QPDFObjectHandle const&amp; item) const
122 121 bool
123 122 QPDFObjectHandle::hasKey(std::string const& key) const
124 123 {
125   - auto dict = as_dictionary(strict);
126   - if (dict) {
127   - return dict.hasKey(key);
  124 + if (Dictionary dict = *this) {
  125 + return dict.contains(key);
128 126 } else {
129 127 typeWarning("dictionary", "returning false for a key containment request");
130 128 QTC::TC("qpdf", "QPDFObjectHandle dictionary false for hasKey");
... ...
libqpdf/qpdf/QPDFObjectHandle_private.hh
... ... @@ -120,7 +120,6 @@ namespace qpdf
120 120 {
121 121 public:
122 122 // The following methods are not part of the public API.
123   - bool hasKey(std::string const& key) const;
124 123 QPDFObjectHandle getKey(std::string const& key) const;
125 124 std::set<std::string> getKeys();
126 125 std::map<std::string, QPDFObjectHandle> const& getAsMap() const;
... ...