aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-04-24 15:31:32 +0200
committerJay Berkenbilt <ejb@ql.org>2022-04-24 15:31:32 +0200
commit4be2f3604939de8589dd2206fdf3d1a85033f171 (patch)
treee4a861e9e77bd3b56462f7c996cfec931f8b0b2f /libqpdf
parentb8d0b0b6388db732fee0e9fb95af0884704bf423 (diff)
downloadqpdf-4be2f3604939de8589dd2206fdf3d1a85033f171.tar.zst
Deprecate replaceOrRemoveKey -- it's the same as replaceKey
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDFObjectHandle.cc9
-rw-r--r--libqpdf/QPDFPageLabelDocumentHelper.cc6
-rw-r--r--libqpdf/QPDF_Dictionary.cc24
-rw-r--r--libqpdf/QPDF_Stream.cc4
-rw-r--r--libqpdf/qpdf-c.cc4
-rw-r--r--libqpdf/qpdf/QPDF_Dictionary.hh7
6 files changed, 20 insertions, 34 deletions
diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc
index 516e38b9..297221df 100644
--- a/libqpdf/QPDFObjectHandle.cc
+++ b/libqpdf/QPDFObjectHandle.cc
@@ -1295,14 +1295,7 @@ void
QPDFObjectHandle::replaceOrRemoveKey(
std::string const& key, QPDFObjectHandle const& value)
{
- if (isDictionary()) {
- checkOwnership(value);
- dynamic_cast<QPDF_Dictionary*>(obj.get())->replaceOrRemoveKey(
- key, value);
- } else {
- typeWarning("dictionary", "ignoring key removal/replacement request");
- QTC::TC("qpdf", "QPDFObjectHandle dictionary ignoring removereplace");
- }
+ replaceKey(key, value);
}
// Stream accessors
diff --git a/libqpdf/QPDFPageLabelDocumentHelper.cc b/libqpdf/QPDFPageLabelDocumentHelper.cc
index 5b2d4358..babfd5aa 100644
--- a/libqpdf/QPDFPageLabelDocumentHelper.cc
+++ b/libqpdf/QPDFPageLabelDocumentHelper.cc
@@ -44,9 +44,9 @@ QPDFPageLabelDocumentHelper::getLabelForPage(long long page_idx)
QIntC::range_check(start, offset);
start += offset;
result = QPDFObjectHandle::newDictionary();
- result.replaceOrRemoveKey("/S", S);
- result.replaceOrRemoveKey("/P", P);
- result.replaceOrRemoveKey("/St", QPDFObjectHandle::newInteger(start));
+ result.replaceKey("/S", S);
+ result.replaceKey("/P", P);
+ result.replaceKey("/St", QPDFObjectHandle::newInteger(start));
return result;
}
diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc
index 1655f53a..0423f41f 100644
--- a/libqpdf/QPDF_Dictionary.cc
+++ b/libqpdf/QPDF_Dictionary.cc
@@ -115,11 +115,16 @@ QPDF_Dictionary::getAsMap() const
}
void
-QPDF_Dictionary::replaceKey(
- std::string const& key, QPDFObjectHandle const& value)
+QPDF_Dictionary::replaceKey(std::string const& key, QPDFObjectHandle value)
{
- // add or replace value
- this->items[key] = value;
+ if (value.isNull()) {
+ // The PDF spec doesn't distinguish between keys with null
+ // values and missing keys.
+ removeKey(key);
+ } else {
+ // add or replace value
+ this->items[key] = value;
+ }
}
void
@@ -128,14 +133,3 @@ QPDF_Dictionary::removeKey(std::string const& key)
// no-op if key does not exist
this->items.erase(key);
}
-
-void
-QPDF_Dictionary::replaceOrRemoveKey(
- std::string const& key, QPDFObjectHandle value)
-{
- if (value.isNull()) {
- removeKey(key);
- } else {
- replaceKey(key, value);
- }
-}
diff --git a/libqpdf/QPDF_Stream.cc b/libqpdf/QPDF_Stream.cc
index cbc65611..2d0554b9 100644
--- a/libqpdf/QPDF_Stream.cc
+++ b/libqpdf/QPDF_Stream.cc
@@ -604,8 +604,8 @@ QPDF_Stream::replaceFilterData(
QPDFObjectHandle const& decode_parms,
size_t length)
{
- this->stream_dict.replaceOrRemoveKey("/Filter", filter);
- this->stream_dict.replaceOrRemoveKey("/DecodeParms", decode_parms);
+ this->stream_dict.replaceKey("/Filter", filter);
+ this->stream_dict.replaceKey("/DecodeParms", decode_parms);
if (length == 0) {
QTC::TC("qpdf", "QPDF_Stream unknown stream length");
this->stream_dict.removeKey("/Length");
diff --git a/libqpdf/qpdf-c.cc b/libqpdf/qpdf-c.cc
index 9ced5b12..926768ad 100644
--- a/libqpdf/qpdf-c.cc
+++ b/libqpdf/qpdf-c.cc
@@ -438,7 +438,7 @@ qpdf_set_info_key(qpdf_data qpdf, char const* key, char const* value)
}
QPDFObjectHandle info = trailer.getKey("/Info");
- info.replaceOrRemoveKey(key, value_object);
+ info.replaceKey(key, value_object);
}
QPDF_BOOL
@@ -1919,7 +1919,7 @@ qpdf_oh_replace_or_remove_key(
{
do_with_oh_void(qpdf, oh, [qpdf, key, item](QPDFObjectHandle& o) {
QTC::TC("qpdf", "qpdf-c called qpdf_oh_replace_or_remove_key");
- o.replaceOrRemoveKey(key, qpdf_oh_item_internal(qpdf, item));
+ o.replaceKey(key, qpdf_oh_item_internal(qpdf, item));
});
}
diff --git a/libqpdf/qpdf/QPDF_Dictionary.hh b/libqpdf/qpdf/QPDF_Dictionary.hh
index 42ee6cf9..3c42cc0e 100644
--- a/libqpdf/qpdf/QPDF_Dictionary.hh
+++ b/libqpdf/qpdf/QPDF_Dictionary.hh
@@ -27,12 +27,11 @@ class QPDF_Dictionary: public QPDFObject
std::set<std::string> getKeys();
std::map<std::string, QPDFObjectHandle> const& getAsMap() const;
- // Replace value of key, adding it if it does not exist
- void replaceKey(std::string const& key, QPDFObjectHandle const&);
+ // If value is null, remove key; otherwise, replace the value of
+ // key, adding it if it does not exist.
+ void replaceKey(std::string const& key, QPDFObjectHandle value);
// Remove key, doing nothing if key does not exist
void removeKey(std::string const& key);
- // If object is null, remove key; otherwise, replace key
- void replaceOrRemoveKey(std::string const& key, QPDFObjectHandle);
protected:
virtual void releaseResolved();