diff options
author | Jay Berkenbilt <ejb@ql.org> | 2018-12-17 23:36:06 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2018-12-18 22:45:48 +0100 |
commit | 077d3d451204393d17b9a14c2145487c35fce572 (patch) | |
tree | 1d5d02895b95d3375ccac7cf24a0c6615d4a1c74 | |
parent | 9caf005d89f039b56f027d9fe20fe2f475927597 (diff) | |
download | qpdf-077d3d451204393d17b9a14c2145487c35fce572.tar.zst |
Add QPDFObjectHandle::wrapInArray()
Wrap an object in an array if it is not already an array.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | include/qpdf/QPDFObjectHandle.hh | 6 | ||||
-rw-r--r-- | libqpdf/QPDFObjectHandle.cc | 12 |
3 files changed, 26 insertions, 0 deletions
@@ -1,3 +1,11 @@ +2018-12-18 Jay Berkenbilt <ejb@ql.org> + + * New method QPDFObjectHandle::wrapInArray returns the object + itself if it is an array. Otherwise, it returns an array + containing the object. This is useful for dealing with PDF data + that is sometimes expressed as a single element and sometimes + expressed as an array, which is a somewhat common PDF idiom. + 2018-10-11 Jay Berkenbilt <ejb@ql.org> * Files generated by autogen.sh are now committed so that it is diff --git a/include/qpdf/QPDFObjectHandle.hh b/include/qpdf/QPDFObjectHandle.hh index 0f33b3fd..88f071d2 100644 --- a/include/qpdf/QPDFObjectHandle.hh +++ b/include/qpdf/QPDFObjectHandle.hh @@ -255,6 +255,12 @@ class QPDFObjectHandle // Public factory methods + // Wrap an object in an array if it is not already an array. This + // is a helper for cases in which something in a PDF may either be + // a single item or an array of items, which is a common idiom. + QPDF_DLL + QPDFObjectHandle wrapInArray(); + // Construct an object of any type from a string representation of // the object. Throws QPDFExc with an empty filename and an // offset into the string if there is an error. Any indirect diff --git a/libqpdf/QPDFObjectHandle.cc b/libqpdf/QPDFObjectHandle.cc index f4a8a0a4..f26ee931 100644 --- a/libqpdf/QPDFObjectHandle.cc +++ b/libqpdf/QPDFObjectHandle.cc @@ -1236,6 +1236,18 @@ QPDFObjectHandle::unparseBinary() } QPDFObjectHandle +QPDFObjectHandle::wrapInArray() +{ + if (isArray()) + { + return *this; + } + QPDFObjectHandle result = QPDFObjectHandle::newArray(); + result.appendItem(*this); + return result; +} + +QPDFObjectHandle QPDFObjectHandle::parse(std::string const& object_str, std::string const& object_description) { |