Add method QPDFObjectHandle::getKeyIfDict

This commit is contained in:
m-holger 2022-02-06 02:13:04 +00:00 committed by Jay Berkenbilt
parent 2ed5f49a79
commit 8371060340
5 changed files with 15 additions and 0 deletions

View File

@ -810,6 +810,8 @@ class QPDFObjectHandle
// returned.
QPDF_DLL
QPDFObjectHandle getKey(std::string const&);
QPDF_DLL
QPDFObjectHandle getKeyIfDict(std::string const&);
// Return all keys. Keys with null values are treated as if
// they are not present. This is as per the PDF spec.
QPDF_DLL

View File

@ -1150,6 +1150,12 @@ QPDFObjectHandle::getKey(std::string const& key)
return result;
}
QPDFObjectHandle
QPDFObjectHandle::getKeyIfDict(std::string const& key)
{
return isNull() ? newNull() : getKey(key);
}
std::set<std::string>
QPDFObjectHandle::getKeys()
{

View File

@ -20,6 +20,7 @@ WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operatio
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
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
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
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
WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operation for inlineimage attempted on object of type integer: returning empty data
WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 362: operation for integer attempted on object of type dictionary: returning 0
WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operation for name attempted on object of type integer: returning dummy name
@ -32,6 +33,7 @@ One error
WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 385: operation for string attempted on object of type name: returning empty string
One error
WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 362 -> dictionary key /Quack: operation for string attempted on object of type null: returning empty string
WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 362 -> dictionary key /Quack: operation for string attempted on object of type null: returning empty string
Two errors
WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 384: returning null for out of bounds array access
WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 384 -> null returned from invalid array access: operation for string attempted on object of type null: returning empty string

View File

@ -20,6 +20,7 @@ WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary at
WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: ignoring key removal/replacement request
WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: ignoring key replacement request
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
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
WARNING: object-types.pdf, object 8 0 at offset 669: operation for inlineimage attempted on object of type integer: returning empty data
WARNING: object-types.pdf, object 8 0 at offset 687: operation for integer attempted on object of type dictionary: returning 0
WARNING: object-types.pdf, object 8 0 at offset 669: operation for name attempted on object of type integer: returning dummy name
@ -32,6 +33,7 @@ One error
WARNING: object-types.pdf, object 8 0 at offset 724: operation for string attempted on object of type name: returning empty string
One error
WARNING: object-types.pdf, object 8 0 at offset 687 -> dictionary key /Quack: operation for string attempted on object of type null: returning empty string
WARNING: object-types.pdf, object 8 0 at offset 687 -> dictionary key /Quack: operation for string attempted on object of type null: returning empty string
Two errors
WARNING: object-types.pdf, object 8 0 at offset 717: returning null for out of bounds array access
WARNING: object-types.pdf, object 8 0 at offset 717 -> null returned from invalid array access: operation for string attempted on object of type null: returning empty string

View File

@ -1568,6 +1568,8 @@ static void test_42(QPDF& pdf, char const* arg2)
integer.replaceOrRemoveKey("/Potato", null);
integer.replaceOrRemoveKey("/Potato", QPDFObjectHandle::newInteger(1));
integer.replaceKey("/Potato", QPDFObjectHandle::newInteger(1));
null.getKeyIfDict("/Integer").getKeyIfDict("/Potato").assertNull();
qtest.getKey("/Integer").getKeyIfDict("/Potato");
qtest.getKey("/Integer").getKey("/Potato");
assert(integer.getInlineImageValue().empty());
assert(0 == dictionary.getIntValue());
@ -1582,6 +1584,7 @@ static void test_42(QPDF& pdf, char const* arg2)
assert(array.getArrayItem(0).getStringValue().empty());
std::cerr << "One error\n";
assert(dictionary.getKey("/Quack").getStringValue().empty());
assert(dictionary.getKeyIfDict("/Quack").getStringValue().empty());
assert(array.getArrayItem(1).isDictionary());
assert(array.getArrayItem(1).getKey("/K").isArray());
assert(array.getArrayItem(1).getKey("/K").getArrayItem(0).isName());