Commit cbd5db35abcaecc222c93339b3fb4da0076ee402
1 parent
72bda79c
Refactor `QPDFEFStreamObjectHelper`: simplify dictionary access, replace redunda…
…nt checks, and streamline string handling.
Showing
1 changed file
with
19 additions
and
20 deletions
libqpdf/QPDFEFStreamObjectHelper.cc
| ... | ... | @@ -5,8 +5,11 @@ |
| 5 | 5 | #include <qpdf/Pl_MD5.hh> |
| 6 | 6 | #include <qpdf/QIntC.hh> |
| 7 | 7 | #include <qpdf/QPDF.hh> |
| 8 | +#include <qpdf/QPDFObjectHandle_private.hh> | |
| 8 | 9 | #include <qpdf/QUtil.hh> |
| 9 | 10 | |
| 11 | +using namespace qpdf; | |
| 12 | + | |
| 10 | 13 | class QPDFEFStreamObjectHelper::Members |
| 11 | 14 | { |
| 12 | 15 | }; |
| ... | ... | @@ -19,41 +22,38 @@ QPDFEFStreamObjectHelper::QPDFEFStreamObjectHelper(QPDFObjectHandle oh) : |
| 19 | 22 | QPDFObjectHandle |
| 20 | 23 | QPDFEFStreamObjectHelper::getParam(std::string const& pkey) |
| 21 | 24 | { |
| 22 | - auto params = oh().getDict().getKey("/Params"); | |
| 23 | - if (params.isDictionary()) { | |
| 24 | - return params.getKey(pkey); | |
| 25 | + if (auto result = oh().getDict()["/Params"][pkey]) { | |
| 26 | + return result; | |
| 25 | 27 | } |
| 26 | - return QPDFObjectHandle::newNull(); | |
| 28 | + return {}; | |
| 27 | 29 | } |
| 28 | 30 | |
| 29 | 31 | void |
| 30 | 32 | QPDFEFStreamObjectHelper::setParam(std::string const& pkey, QPDFObjectHandle const& pval) |
| 31 | 33 | { |
| 32 | - auto params = oh().getDict().getKey("/Params"); | |
| 33 | - if (!params.isDictionary()) { | |
| 34 | - params = oh().getDict().replaceKeyAndGetNew("/Params", QPDFObjectHandle::newDictionary()); | |
| 34 | + if (Dictionary Params = oh().getDict()["/Params"]) { | |
| 35 | + Params.replaceKey(pkey, pval); | |
| 36 | + return; | |
| 35 | 37 | } |
| 36 | - params.replaceKey(pkey, pval); | |
| 38 | + oh().getDict().replaceKey("/Params", Dictionary({{pkey, pval}})); | |
| 37 | 39 | } |
| 38 | 40 | |
| 39 | 41 | std::string |
| 40 | 42 | QPDFEFStreamObjectHelper::getCreationDate() |
| 41 | 43 | { |
| 42 | - auto val = getParam("/CreationDate"); | |
| 43 | - if (val.isString()) { | |
| 44 | - return val.getUTF8Value(); | |
| 44 | + if (String CreationDate = getParam("/CreationDate")) { | |
| 45 | + return CreationDate.utf8_value(); | |
| 45 | 46 | } |
| 46 | - return ""; | |
| 47 | + return {}; | |
| 47 | 48 | } |
| 48 | 49 | |
| 49 | 50 | std::string |
| 50 | 51 | QPDFEFStreamObjectHelper::getModDate() |
| 51 | 52 | { |
| 52 | - auto val = getParam("/ModDate"); | |
| 53 | - if (val.isString()) { | |
| 54 | - return val.getUTF8Value(); | |
| 53 | + if (String ModDate = getParam("/ModDate")) { | |
| 54 | + return ModDate.utf8_value(); | |
| 55 | 55 | } |
| 56 | - return ""; | |
| 56 | + return {}; | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | size_t |
| ... | ... | @@ -82,11 +82,10 @@ QPDFEFStreamObjectHelper::getSubtype() |
| 82 | 82 | std::string |
| 83 | 83 | QPDFEFStreamObjectHelper::getChecksum() |
| 84 | 84 | { |
| 85 | - auto val = getParam("/CheckSum"); | |
| 86 | - if (val.isString()) { | |
| 87 | - return val.getStringValue(); | |
| 85 | + if (String CheckSum = getParam("/CheckSum")) { | |
| 86 | + return CheckSum.value(); | |
| 88 | 87 | } |
| 89 | - return ""; | |
| 88 | + return {}; | |
| 90 | 89 | } |
| 91 | 90 | |
| 92 | 91 | QPDFEFStreamObjectHelper | ... | ... |