Commit 710d2e54f0762b7702640766d33b7e0977ba69de
Committed by
Jay Berkenbilt
1 parent
823926f8
Allow testing for subtype without specifying type in isDictionaryOfType etc
Accept empty string as type parameter in QPDFObjectHandle::isDictionaryOfType and isStreamOfType to allow for dictionaries with optional type.
Showing
3 changed files
with
7 additions
and
12 deletions
libqpdf/QPDFObjectHandle.cc
| @@ -507,15 +507,9 @@ bool | @@ -507,15 +507,9 @@ bool | ||
| 507 | QPDFObjectHandle::isDictionaryOfType(std::string const& type, | 507 | QPDFObjectHandle::isDictionaryOfType(std::string const& type, |
| 508 | std::string const& subtype) | 508 | std::string const& subtype) |
| 509 | { | 509 | { |
| 510 | - if (isDictionary() && getKey("/Type").isNameAndEquals(type)) | ||
| 511 | - { | ||
| 512 | - return (subtype == "") || | ||
| 513 | - (hasKey("/Subtype") && getKey("/Subtype").isNameAndEquals(subtype)); | ||
| 514 | - } | ||
| 515 | - else | ||
| 516 | - { | ||
| 517 | - return false; | ||
| 518 | - } | 510 | + return isDictionary() && |
| 511 | + (type.empty() || getKey("/Type").isNameAndEquals(type)) && | ||
| 512 | + (subtype.empty() || getKey("/Subtype").isNameAndEquals(subtype)); | ||
| 519 | } | 513 | } |
| 520 | 514 | ||
| 521 | bool | 515 | bool |
qpdf/qpdf-ctest.c
| @@ -724,7 +724,7 @@ static void test25(char const* infile, | @@ -724,7 +724,7 @@ static void test25(char const* infile, | ||
| 724 | assert(qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test", "/Marvin")); | 724 | assert(qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test", "/Marvin")); |
| 725 | assert(! qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test2", "")); | 725 | assert(! qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test2", "")); |
| 726 | assert(! qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test", "/M")); | 726 | assert(! qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "/Test", "/M")); |
| 727 | - assert(! qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "", "")); | 727 | + assert(qpdf_oh_is_dictionary_of_type(qpdf, new_dict, "", "")); |
| 728 | qpdf_oh new_array = qpdf_oh_new_array(qpdf); | 728 | qpdf_oh new_array = qpdf_oh_new_array(qpdf); |
| 729 | qpdf_oh_replace_or_remove_key( | 729 | qpdf_oh_replace_or_remove_key( |
| 730 | qpdf, new_dict, "/A", qpdf_oh_new_null(qpdf)); | 730 | qpdf, new_dict, "/A", qpdf_oh_new_null(qpdf)); |
qpdf/test_driver.cc
| @@ -3110,11 +3110,12 @@ static void test_82(QPDF& pdf, char const* arg2) | @@ -3110,11 +3110,12 @@ static void test_82(QPDF& pdf, char const* arg2) | ||
| 3110 | assert(dict.isDictionaryOfType( "/Test", "")); | 3110 | assert(dict.isDictionaryOfType( "/Test", "")); |
| 3111 | assert(dict.isDictionaryOfType("/Test")); | 3111 | assert(dict.isDictionaryOfType("/Test")); |
| 3112 | assert(dict.isDictionaryOfType("/Test", "/Marvin")); | 3112 | assert(dict.isDictionaryOfType("/Test", "/Marvin")); |
| 3113 | + assert(dict.isDictionaryOfType("", "/Marvin")); | ||
| 3114 | + assert(dict.isDictionaryOfType("", "")); | ||
| 3113 | assert(! dict.isDictionaryOfType("/Test2", "")); | 3115 | assert(! dict.isDictionaryOfType("/Test2", "")); |
| 3114 | assert(! dict.isDictionaryOfType("/Test2", "/Marvin")); | 3116 | assert(! dict.isDictionaryOfType("/Test2", "/Marvin")); |
| 3115 | assert(! dict.isDictionaryOfType("/Test", "/M")); | 3117 | assert(! dict.isDictionaryOfType("/Test", "/M")); |
| 3116 | - assert(! dict.isDictionaryOfType("", "/Marvin")); | ||
| 3117 | - assert(! dict.isDictionaryOfType("", "")); | 3118 | + assert(! name.isDictionaryOfType("", "")); |
| 3118 | dict = QPDFObjectHandle::parse("<</A 1 /Type null /Subtype /Marvin>>"); | 3119 | dict = QPDFObjectHandle::parse("<</A 1 /Type null /Subtype /Marvin>>"); |
| 3119 | assert(! dict.isDictionaryOfType("/Test")); | 3120 | assert(! dict.isDictionaryOfType("/Test")); |
| 3120 | dict = QPDFObjectHandle::parse("<</A 1 /Type (Test) /Subtype /Marvin>>"); | 3121 | dict = QPDFObjectHandle::parse("<</A 1 /Type (Test) /Subtype /Marvin>>"); |