aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF_Dictionary.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-04-24 16:08:32 +0200
committerJay Berkenbilt <ejb@ql.org>2022-04-24 16:08:32 +0200
commit08ba21cf4935fec39d3454714c03d36ff6a6b836 (patch)
tree4eda1a94c86f3e76e9d4a1d43fa46d57004f05e9 /libqpdf/QPDF_Dictionary.cc
parent4be2f3604939de8589dd2206fdf3d1a85033f171 (diff)
downloadqpdf-08ba21cf4935fec39d3454714c03d36ff6a6b836.tar.zst
Fix some bugs around null values in dictionaries
Make it so that a key with a null value is always treated as not being present. This was inconsistent before.
Diffstat (limited to 'libqpdf/QPDF_Dictionary.cc')
-rw-r--r--libqpdf/QPDF_Dictionary.cc36
1 files changed, 16 insertions, 20 deletions
diff --git a/libqpdf/QPDF_Dictionary.cc b/libqpdf/QPDF_Dictionary.cc
index 0423f41f..c3343b21 100644
--- a/libqpdf/QPDF_Dictionary.cc
+++ b/libqpdf/QPDF_Dictionary.cc
@@ -24,12 +24,11 @@ std::string
QPDF_Dictionary::unparse()
{
std::string result = "<< ";
- for (std::map<std::string, QPDFObjectHandle>::iterator iter =
- this->items.begin();
- iter != this->items.end();
- ++iter) {
- result += QPDF_Name::normalizeName((*iter).first) + " " +
- (*iter).second.unparse() + " ";
+ for (auto& iter : this->items) {
+ if (!iter.second.isNull()) {
+ result += QPDF_Name::normalizeName(iter.first) + " " +
+ iter.second.unparse() + " ";
+ }
}
result += ">>";
return result;
@@ -39,12 +38,11 @@ JSON
QPDF_Dictionary::getJSON()
{
JSON j = JSON::makeDictionary();
- for (std::map<std::string, QPDFObjectHandle>::iterator iter =
- this->items.begin();
- iter != this->items.end();
- ++iter) {
- j.addDictionaryMember(
- QPDF_Name::normalizeName((*iter).first), (*iter).second.getJSON());
+ for (auto& iter : this->items) {
+ if (!iter.second.isNull()) {
+ j.addDictionaryMember(
+ QPDF_Name::normalizeName(iter.first), iter.second.getJSON());
+ }
}
return j;
}
@@ -78,9 +76,10 @@ QPDF_Dictionary::getKey(std::string const& key)
{
// PDF spec says fetching a non-existent key from a dictionary
// returns the null object.
- if (this->items.count(key)) {
+ auto item = this->items.find(key);
+ if (item != this->items.end()) {
// May be a null object
- return (*(this->items.find(key))).second;
+ return item->second;
} else {
QPDFObjectHandle null = QPDFObjectHandle::newNull();
QPDF* qpdf = 0;
@@ -97,12 +96,9 @@ std::set<std::string>
QPDF_Dictionary::getKeys()
{
std::set<std::string> result;
- for (std::map<std::string, QPDFObjectHandle>::const_iterator iter =
- this->items.begin();
- iter != this->items.end();
- ++iter) {
- if (hasKey((*iter).first)) {
- result.insert((*iter).first);
+ for (auto& iter : this->items) {
+ if (!iter.second.isNull()) {
+ result.insert(iter.first);
}
}
return result;