Commit 08dcf84c2c8cb04e795b7735fdb594e7487cdee3
1 parent
cbeaf5a8
Replace `hasKey` with `contains` in `BaseDictionary` and `QPDFObjectHandle`, ref…
…actor implementation to simplify null handling and align with API conventions.
Showing
3 changed files
with
5 additions
and
7 deletions
include/qpdf/ObjectHandle.hh
| @@ -83,6 +83,7 @@ namespace qpdf | @@ -83,6 +83,7 @@ namespace qpdf | ||
| 83 | QPDFObjectHandle operator[](size_t n) const; | 83 | QPDFObjectHandle operator[](size_t n) const; |
| 84 | QPDFObjectHandle operator[](int n) const; | 84 | QPDFObjectHandle operator[](int n) const; |
| 85 | 85 | ||
| 86 | + bool contains(std::string const& key) const; | ||
| 86 | QPDFObjectHandle const& operator[](std::string const& key) const; | 87 | QPDFObjectHandle const& operator[](std::string const& key) const; |
| 87 | 88 | ||
| 88 | std::shared_ptr<QPDFObject> copy(bool shallow = false) const; | 89 | std::shared_ptr<QPDFObject> copy(bool shallow = false) const; |
libqpdf/QPDF_Dictionary.cc
| @@ -30,10 +30,9 @@ BaseHandle::operator[](std::string const& key) const | @@ -30,10 +30,9 @@ BaseHandle::operator[](std::string const& key) const | ||
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | bool | 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 | QPDFObjectHandle | 38 | QPDFObjectHandle |
| @@ -122,9 +121,8 @@ QPDFObjectHandle::checkOwnership(QPDFObjectHandle const& item) const | @@ -122,9 +121,8 @@ QPDFObjectHandle::checkOwnership(QPDFObjectHandle const& item) const | ||
| 122 | bool | 121 | bool |
| 123 | QPDFObjectHandle::hasKey(std::string const& key) const | 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 | } else { | 126 | } else { |
| 129 | typeWarning("dictionary", "returning false for a key containment request"); | 127 | typeWarning("dictionary", "returning false for a key containment request"); |
| 130 | QTC::TC("qpdf", "QPDFObjectHandle dictionary false for hasKey"); | 128 | QTC::TC("qpdf", "QPDFObjectHandle dictionary false for hasKey"); |
libqpdf/qpdf/QPDFObjectHandle_private.hh
| @@ -120,7 +120,6 @@ namespace qpdf | @@ -120,7 +120,6 @@ namespace qpdf | ||
| 120 | { | 120 | { |
| 121 | public: | 121 | public: |
| 122 | // The following methods are not part of the public API. | 122 | // The following methods are not part of the public API. |
| 123 | - bool hasKey(std::string const& key) const; | ||
| 124 | QPDFObjectHandle getKey(std::string const& key) const; | 123 | QPDFObjectHandle getKey(std::string const& key) const; |
| 125 | std::set<std::string> getKeys(); | 124 | std::set<std::string> getKeys(); |
| 126 | std::map<std::string, QPDFObjectHandle> const& getAsMap() const; | 125 | std::map<std::string, QPDFObjectHandle> const& getAsMap() const; |