Commit 83710603402229090dd5b1eefdebed044efe8d87
Committed by
Jay Berkenbilt
1 parent
2ed5f49a
Add method QPDFObjectHandle::getKeyIfDict
Showing
5 changed files
with
15 additions
and
0 deletions
include/qpdf/QPDFObjectHandle.hh
| @@ -810,6 +810,8 @@ class QPDFObjectHandle | @@ -810,6 +810,8 @@ class QPDFObjectHandle | ||
| 810 | // returned. | 810 | // returned. |
| 811 | QPDF_DLL | 811 | QPDF_DLL |
| 812 | QPDFObjectHandle getKey(std::string const&); | 812 | QPDFObjectHandle getKey(std::string const&); |
| 813 | + QPDF_DLL | ||
| 814 | + QPDFObjectHandle getKeyIfDict(std::string const&); | ||
| 813 | // Return all keys. Keys with null values are treated as if | 815 | // Return all keys. Keys with null values are treated as if |
| 814 | // they are not present. This is as per the PDF spec. | 816 | // they are not present. This is as per the PDF spec. |
| 815 | QPDF_DLL | 817 | QPDF_DLL |
libqpdf/QPDFObjectHandle.cc
| @@ -1150,6 +1150,12 @@ QPDFObjectHandle::getKey(std::string const& key) | @@ -1150,6 +1150,12 @@ QPDFObjectHandle::getKey(std::string const& key) | ||
| 1150 | return result; | 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 | std::set<std::string> | 1159 | std::set<std::string> |
| 1154 | QPDFObjectHandle::getKeys() | 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,6 +20,7 @@ WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 429: operatio | ||
| 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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,6 +33,7 @@ One error | ||
| 32 | 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 | 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 | One error | 34 | One error |
| 34 | 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 | 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 | Two errors | 37 | Two errors |
| 36 | WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 384: returning null for out of bounds array access | 38 | WARNING: object-types-os.pdf object stream 1, object 7 0 at offset 384: returning null for out of bounds array access |
| 37 | 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 | 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,6 +20,7 @@ WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary at | ||
| 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 | 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 | WARNING: object-types.pdf, object 8 0 at offset 669: operation for dictionary attempted on object of type integer: ignoring key replacement request | 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 | 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 | 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 | WARNING: object-types.pdf, object 8 0 at offset 669: operation for inlineimage attempted on object of type integer: returning empty data | 24 | WARNING: object-types.pdf, object 8 0 at offset 669: operation for inlineimage attempted on object of type integer: returning empty data |
| 24 | WARNING: object-types.pdf, object 8 0 at offset 687: operation for integer attempted on object of type dictionary: returning 0 | 25 | WARNING: object-types.pdf, object 8 0 at offset 687: operation for integer attempted on object of type dictionary: returning 0 |
| 25 | WARNING: object-types.pdf, object 8 0 at offset 669: operation for name attempted on object of type integer: returning dummy name | 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,6 +33,7 @@ One error | ||
| 32 | WARNING: object-types.pdf, object 8 0 at offset 724: operation for string attempted on object of type name: returning empty string | 33 | WARNING: object-types.pdf, object 8 0 at offset 724: operation for string attempted on object of type name: returning empty string |
| 33 | One error | 34 | One error |
| 34 | 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 | 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 | Two errors | 37 | Two errors |
| 36 | WARNING: object-types.pdf, object 8 0 at offset 717: returning null for out of bounds array access | 38 | WARNING: object-types.pdf, object 8 0 at offset 717: returning null for out of bounds array access |
| 37 | 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 | 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& pdf, char const* arg2) | @@ -1568,6 +1568,8 @@ static void test_42(QPDF& pdf, char const* arg2) | ||
| 1568 | integer.replaceOrRemoveKey("/Potato", null); | 1568 | integer.replaceOrRemoveKey("/Potato", null); |
| 1569 | integer.replaceOrRemoveKey("/Potato", QPDFObjectHandle::newInteger(1)); | 1569 | integer.replaceOrRemoveKey("/Potato", QPDFObjectHandle::newInteger(1)); |
| 1570 | integer.replaceKey("/Potato", QPDFObjectHandle::newInteger(1)); | 1570 | integer.replaceKey("/Potato", QPDFObjectHandle::newInteger(1)); |
| 1571 | + null.getKeyIfDict("/Integer").getKeyIfDict("/Potato").assertNull(); | ||
| 1572 | + qtest.getKey("/Integer").getKeyIfDict("/Potato"); | ||
| 1571 | qtest.getKey("/Integer").getKey("/Potato"); | 1573 | qtest.getKey("/Integer").getKey("/Potato"); |
| 1572 | assert(integer.getInlineImageValue().empty()); | 1574 | assert(integer.getInlineImageValue().empty()); |
| 1573 | assert(0 == dictionary.getIntValue()); | 1575 | assert(0 == dictionary.getIntValue()); |
| @@ -1582,6 +1584,7 @@ static void test_42(QPDF& pdf, char const* arg2) | @@ -1582,6 +1584,7 @@ static void test_42(QPDF& pdf, char const* arg2) | ||
| 1582 | assert(array.getArrayItem(0).getStringValue().empty()); | 1584 | assert(array.getArrayItem(0).getStringValue().empty()); |
| 1583 | std::cerr << "One error\n"; | 1585 | std::cerr << "One error\n"; |
| 1584 | assert(dictionary.getKey("/Quack").getStringValue().empty()); | 1586 | assert(dictionary.getKey("/Quack").getStringValue().empty()); |
| 1587 | + assert(dictionary.getKeyIfDict("/Quack").getStringValue().empty()); | ||
| 1585 | assert(array.getArrayItem(1).isDictionary()); | 1588 | assert(array.getArrayItem(1).isDictionary()); |
| 1586 | assert(array.getArrayItem(1).getKey("/K").isArray()); | 1589 | assert(array.getArrayItem(1).getKey("/K").isArray()); |
| 1587 | assert(array.getArrayItem(1).getKey("/K").getArrayItem(0).isName()); | 1590 | assert(array.getArrayItem(1).getKey("/K").getArrayItem(0).isName()); |