Commit 83710603402229090dd5b1eefdebed044efe8d87

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 2ed5f49a

Add method QPDFObjectHandle::getKeyIfDict

include/qpdf/QPDFObjectHandle.hh
... ... @@ -810,6 +810,8 @@ class QPDFObjectHandle
810 810 // returned.
811 811 QPDF_DLL
812 812 QPDFObjectHandle getKey(std::string const&);
  813 + QPDF_DLL
  814 + QPDFObjectHandle getKeyIfDict(std::string const&);
813 815 // Return all keys. Keys with null values are treated as if
814 816 // they are not present. This is as per the PDF spec.
815 817 QPDF_DLL
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -1150,6 +1150,12 @@ QPDFObjectHandle::getKey(std::string const& key)
1150 1150 return result;
1151 1151 }
1152 1152  
  1153 +QPDFObjectHandle
  1154 +QPDFObjectHandle::getKeyIfDict(std::string const& key)
  1155 +{
  1156 + return isNull() ? newNull() : getKey(key);
  1157 +}
  1158 +
1153 1159 std::set<std::string>
1154 1160 QPDFObjectHandle::getKeys()
1155 1161 {
... ...
qpdf/qtest/qpdf/object-types-os.out
... ... @@ -20,6 +20,7 @@ WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operatio
20 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
21 21 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 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
  23 +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 24 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
24 25 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
25 26 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
32 33 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
33 34 One error
34 35 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
  36 +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
35 37 Two errors
36 38 WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 384: returning null for out of bounds array access
37 39 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
... ...
qpdf/qtest/qpdf/object-types.out
... ... @@ -20,6 +20,7 @@ WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary at
20 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
21 21 WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: ignoring key replacement request
22 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
  23 +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 24 WARNING: object-types.pdf, object 8 0 at offset 669: operation for inlineimage attempted on object of type integer: returning empty data
24 25 WARNING: object-types.pdf, object 8 0 at offset 687: operation for integer attempted on object of type dictionary: returning 0
25 26 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
32 33 WARNING: object-types.pdf, object 8 0 at offset 724: operation for string attempted on object of type name: returning empty string
33 34 One error
34 35 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
  36 +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
35 37 Two errors
36 38 WARNING: object-types.pdf, object 8 0 at offset 717: returning null for out of bounds array access
37 39 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
... ...
qpdf/test_driver.cc
... ... @@ -1568,6 +1568,8 @@ static void test_42(QPDF&amp; pdf, char const* arg2)
1568 1568 integer.replaceOrRemoveKey("/Potato", null);
1569 1569 integer.replaceOrRemoveKey("/Potato", QPDFObjectHandle::newInteger(1));
1570 1570 integer.replaceKey("/Potato", QPDFObjectHandle::newInteger(1));
  1571 + null.getKeyIfDict("/Integer").getKeyIfDict("/Potato").assertNull();
  1572 + qtest.getKey("/Integer").getKeyIfDict("/Potato");
1571 1573 qtest.getKey("/Integer").getKey("/Potato");
1572 1574 assert(integer.getInlineImageValue().empty());
1573 1575 assert(0 == dictionary.getIntValue());
... ... @@ -1582,6 +1584,7 @@ static void test_42(QPDF&amp; pdf, char const* arg2)
1582 1584 assert(array.getArrayItem(0).getStringValue().empty());
1583 1585 std::cerr << "One error\n";
1584 1586 assert(dictionary.getKey("/Quack").getStringValue().empty());
  1587 + assert(dictionary.getKeyIfDict("/Quack").getStringValue().empty());
1585 1588 assert(array.getArrayItem(1).isDictionary());
1586 1589 assert(array.getArrayItem(1).getKey("/K").isArray());
1587 1590 assert(array.getArrayItem(1).getKey("/K").getArrayItem(0).isName());
... ...