Commit 4be2f3604939de8589dd2206fdf3d1a85033f171
1 parent
b8d0b0b6
Deprecate replaceOrRemoveKey -- it's the same as replaceKey
Showing
12 changed files
with
34 additions
and
44 deletions
ChangeLog
include/qpdf/QPDFObjectHandle.hh
| ... | ... | @@ -1023,13 +1023,16 @@ class QPDFObjectHandle |
| 1023 | 1023 | |
| 1024 | 1024 | // Mutator methods for dictionary objects |
| 1025 | 1025 | |
| 1026 | - // Replace value of key, adding it if it does not exist | |
| 1026 | + // Replace value of key, adding it if it does not exist. If value | |
| 1027 | + // is null, remove the key. | |
| 1027 | 1028 | QPDF_DLL |
| 1028 | - void replaceKey(std::string const& key, QPDFObjectHandle const&); | |
| 1029 | + void replaceKey(std::string const& key, QPDFObjectHandle const& value); | |
| 1029 | 1030 | // Remove key, doing nothing if key does not exist |
| 1030 | 1031 | QPDF_DLL |
| 1031 | 1032 | void removeKey(std::string const& key); |
| 1032 | - // If the object is null, remove the key. Otherwise, replace it. | |
| 1033 | + | |
| 1034 | + // ABI: Remove in qpdf 12 | |
| 1035 | + [[deprecated("use replaceKey -- it does the same thing")]] | |
| 1033 | 1036 | QPDF_DLL |
| 1034 | 1037 | void replaceOrRemoveKey(std::string const& key, QPDFObjectHandle const&); |
| 1035 | 1038 | ... | ... |
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -1295,14 +1295,7 @@ void |
| 1295 | 1295 | QPDFObjectHandle::replaceOrRemoveKey( |
| 1296 | 1296 | std::string const& key, QPDFObjectHandle const& value) |
| 1297 | 1297 | { |
| 1298 | - if (isDictionary()) { | |
| 1299 | - checkOwnership(value); | |
| 1300 | - dynamic_cast<QPDF_Dictionary*>(obj.get())->replaceOrRemoveKey( | |
| 1301 | - key, value); | |
| 1302 | - } else { | |
| 1303 | - typeWarning("dictionary", "ignoring key removal/replacement request"); | |
| 1304 | - QTC::TC("qpdf", "QPDFObjectHandle dictionary ignoring removereplace"); | |
| 1305 | - } | |
| 1298 | + replaceKey(key, value); | |
| 1306 | 1299 | } |
| 1307 | 1300 | |
| 1308 | 1301 | // Stream accessors | ... | ... |
libqpdf/QPDFPageLabelDocumentHelper.cc
| ... | ... | @@ -44,9 +44,9 @@ QPDFPageLabelDocumentHelper::getLabelForPage(long long page_idx) |
| 44 | 44 | QIntC::range_check(start, offset); |
| 45 | 45 | start += offset; |
| 46 | 46 | result = QPDFObjectHandle::newDictionary(); |
| 47 | - result.replaceOrRemoveKey("/S", S); | |
| 48 | - result.replaceOrRemoveKey("/P", P); | |
| 49 | - result.replaceOrRemoveKey("/St", QPDFObjectHandle::newInteger(start)); | |
| 47 | + result.replaceKey("/S", S); | |
| 48 | + result.replaceKey("/P", P); | |
| 49 | + result.replaceKey("/St", QPDFObjectHandle::newInteger(start)); | |
| 50 | 50 | return result; |
| 51 | 51 | } |
| 52 | 52 | ... | ... |
libqpdf/QPDF_Dictionary.cc
| ... | ... | @@ -115,11 +115,16 @@ QPDF_Dictionary::getAsMap() const |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | void |
| 118 | -QPDF_Dictionary::replaceKey( | |
| 119 | - std::string const& key, QPDFObjectHandle const& value) | |
| 118 | +QPDF_Dictionary::replaceKey(std::string const& key, QPDFObjectHandle value) | |
| 120 | 119 | { |
| 121 | - // add or replace value | |
| 122 | - this->items[key] = value; | |
| 120 | + if (value.isNull()) { | |
| 121 | + // The PDF spec doesn't distinguish between keys with null | |
| 122 | + // values and missing keys. | |
| 123 | + removeKey(key); | |
| 124 | + } else { | |
| 125 | + // add or replace value | |
| 126 | + this->items[key] = value; | |
| 127 | + } | |
| 123 | 128 | } |
| 124 | 129 | |
| 125 | 130 | void |
| ... | ... | @@ -128,14 +133,3 @@ QPDF_Dictionary::removeKey(std::string const& key) |
| 128 | 133 | // no-op if key does not exist |
| 129 | 134 | this->items.erase(key); |
| 130 | 135 | } |
| 131 | - | |
| 132 | -void | |
| 133 | -QPDF_Dictionary::replaceOrRemoveKey( | |
| 134 | - std::string const& key, QPDFObjectHandle value) | |
| 135 | -{ | |
| 136 | - if (value.isNull()) { | |
| 137 | - removeKey(key); | |
| 138 | - } else { | |
| 139 | - replaceKey(key, value); | |
| 140 | - } | |
| 141 | -} | ... | ... |
libqpdf/QPDF_Stream.cc
| ... | ... | @@ -604,8 +604,8 @@ QPDF_Stream::replaceFilterData( |
| 604 | 604 | QPDFObjectHandle const& decode_parms, |
| 605 | 605 | size_t length) |
| 606 | 606 | { |
| 607 | - this->stream_dict.replaceOrRemoveKey("/Filter", filter); | |
| 608 | - this->stream_dict.replaceOrRemoveKey("/DecodeParms", decode_parms); | |
| 607 | + this->stream_dict.replaceKey("/Filter", filter); | |
| 608 | + this->stream_dict.replaceKey("/DecodeParms", decode_parms); | |
| 609 | 609 | if (length == 0) { |
| 610 | 610 | QTC::TC("qpdf", "QPDF_Stream unknown stream length"); |
| 611 | 611 | this->stream_dict.removeKey("/Length"); | ... | ... |
libqpdf/qpdf-c.cc
| ... | ... | @@ -438,7 +438,7 @@ qpdf_set_info_key(qpdf_data qpdf, char const* key, char const* value) |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | QPDFObjectHandle info = trailer.getKey("/Info"); |
| 441 | - info.replaceOrRemoveKey(key, value_object); | |
| 441 | + info.replaceKey(key, value_object); | |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | QPDF_BOOL |
| ... | ... | @@ -1919,7 +1919,7 @@ qpdf_oh_replace_or_remove_key( |
| 1919 | 1919 | { |
| 1920 | 1920 | do_with_oh_void(qpdf, oh, [qpdf, key, item](QPDFObjectHandle& o) { |
| 1921 | 1921 | QTC::TC("qpdf", "qpdf-c called qpdf_oh_replace_or_remove_key"); |
| 1922 | - o.replaceOrRemoveKey(key, qpdf_oh_item_internal(qpdf, item)); | |
| 1922 | + o.replaceKey(key, qpdf_oh_item_internal(qpdf, item)); | |
| 1923 | 1923 | }); |
| 1924 | 1924 | } |
| 1925 | 1925 | ... | ... |
libqpdf/qpdf/QPDF_Dictionary.hh
| ... | ... | @@ -27,12 +27,11 @@ class QPDF_Dictionary: public QPDFObject |
| 27 | 27 | std::set<std::string> getKeys(); |
| 28 | 28 | std::map<std::string, QPDFObjectHandle> const& getAsMap() const; |
| 29 | 29 | |
| 30 | - // Replace value of key, adding it if it does not exist | |
| 31 | - void replaceKey(std::string const& key, QPDFObjectHandle const&); | |
| 30 | + // If value is null, remove key; otherwise, replace the value of | |
| 31 | + // key, adding it if it does not exist. | |
| 32 | + void replaceKey(std::string const& key, QPDFObjectHandle value); | |
| 32 | 33 | // Remove key, doing nothing if key does not exist |
| 33 | 34 | void removeKey(std::string const& key); |
| 34 | - // If object is null, remove key; otherwise, replace key | |
| 35 | - void replaceOrRemoveKey(std::string const& key, QPDFObjectHandle); | |
| 36 | 35 | |
| 37 | 36 | protected: |
| 38 | 37 | virtual void releaseResolved(); | ... | ... |
qpdf/qpdf.testcov
| ... | ... | @@ -322,7 +322,6 @@ QPDFObjectHandle dictionary empty set for getKeys 0 |
| 322 | 322 | QPDFObjectHandle dictionary empty map for asMap 0 |
| 323 | 323 | QPDFObjectHandle dictionary ignoring replaceKey 0 |
| 324 | 324 | QPDFObjectHandle dictionary ignoring removeKey 0 |
| 325 | -QPDFObjectHandle dictionary ignoring removereplace 0 | |
| 326 | 325 | QPDFObjectHandle numeric non-numeric 0 |
| 327 | 326 | QPDFObjectHandle erase array bounds 0 |
| 328 | 327 | qpdf-c called qpdf_check_pdf 0 | ... | ... |
qpdf/qtest/qpdf/object-types-os.out
| ... | ... | @@ -16,8 +16,7 @@ WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operatio |
| 16 | 16 | WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operation for dictionary attempted on object of type integer: treating as empty |
| 17 | 17 | WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operation for dictionary attempted on object of type integer: returning false for a key containment request |
| 18 | 18 | WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operation for dictionary attempted on object of type integer: ignoring key removal request |
| 19 | -WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operation for dictionary attempted on object of type integer: ignoring key removal/replacement request | |
| 20 | -WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operation for dictionary attempted on object of type integer: ignoring key removal/replacement request | |
| 19 | +WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operation for dictionary attempted on object of type integer: ignoring key replacement request | |
| 21 | 20 | WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operation for dictionary attempted on object of type integer: ignoring key replacement request |
| 22 | 21 | WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operation for dictionary attempted on object of type integer: returning null for attempted key retrieval |
| 23 | 22 | WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operation for dictionary attempted on object of type integer: returning null for attempted key retrieval | ... | ... |
qpdf/qtest/qpdf/object-types.out
| ... | ... | @@ -16,8 +16,7 @@ WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary at |
| 16 | 16 | WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: treating as empty |
| 17 | 17 | WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: returning false for a key containment request |
| 18 | 18 | WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: ignoring key removal request |
| 19 | -WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: ignoring key removal/replacement request | |
| 20 | -WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: ignoring key removal/replacement request | |
| 19 | +WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: ignoring key replacement request | |
| 21 | 20 | WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: ignoring key replacement request |
| 22 | 21 | WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: returning null for attempted key retrieval |
| 23 | 22 | WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: returning null for attempted key retrieval | ... | ... |
qpdf/test_driver.cc
| ... | ... | @@ -1481,8 +1481,7 @@ test_42(QPDF& pdf, char const* arg2) |
| 1481 | 1481 | assert(integer.getKeys().empty()); |
| 1482 | 1482 | assert(false == integer.hasKey("/Potato")); |
| 1483 | 1483 | integer.removeKey("/Potato"); |
| 1484 | - integer.replaceOrRemoveKey("/Potato", null); | |
| 1485 | - integer.replaceOrRemoveKey("/Potato", QPDFObjectHandle::newInteger(1)); | |
| 1484 | + integer.replaceKey("/Potato", null); | |
| 1486 | 1485 | integer.replaceKey("/Potato", QPDFObjectHandle::newInteger(1)); |
| 1487 | 1486 | null.getKeyIfDict("/Integer").getKeyIfDict("/Potato").assertNull(); |
| 1488 | 1487 | qtest.getKey("/Integer").getKeyIfDict("/Potato"); | ... | ... |