Commit 077d3d451204393d17b9a14c2145487c35fce572
1 parent
9caf005d
Add QPDFObjectHandle::wrapInArray()
Wrap an object in an array if it is not already an array.
Showing
3 changed files
with
26 additions
and
0 deletions
ChangeLog
| 1 | +2018-12-18 Jay Berkenbilt <ejb@ql.org> | |
| 2 | + | |
| 3 | + * New method QPDFObjectHandle::wrapInArray returns the object | |
| 4 | + itself if it is an array. Otherwise, it returns an array | |
| 5 | + containing the object. This is useful for dealing with PDF data | |
| 6 | + that is sometimes expressed as a single element and sometimes | |
| 7 | + expressed as an array, which is a somewhat common PDF idiom. | |
| 8 | + | |
| 1 | 9 | 2018-10-11 Jay Berkenbilt <ejb@ql.org> |
| 2 | 10 | |
| 3 | 11 | * Files generated by autogen.sh are now committed so that it is | ... | ... |
include/qpdf/QPDFObjectHandle.hh
| ... | ... | @@ -255,6 +255,12 @@ class QPDFObjectHandle |
| 255 | 255 | |
| 256 | 256 | // Public factory methods |
| 257 | 257 | |
| 258 | + // Wrap an object in an array if it is not already an array. This | |
| 259 | + // is a helper for cases in which something in a PDF may either be | |
| 260 | + // a single item or an array of items, which is a common idiom. | |
| 261 | + QPDF_DLL | |
| 262 | + QPDFObjectHandle wrapInArray(); | |
| 263 | + | |
| 258 | 264 | // Construct an object of any type from a string representation of |
| 259 | 265 | // the object. Throws QPDFExc with an empty filename and an |
| 260 | 266 | // offset into the string if there is an error. Any indirect | ... | ... |
libqpdf/QPDFObjectHandle.cc
| ... | ... | @@ -1236,6 +1236,18 @@ QPDFObjectHandle::unparseBinary() |
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | QPDFObjectHandle |
| 1239 | +QPDFObjectHandle::wrapInArray() | |
| 1240 | +{ | |
| 1241 | + if (isArray()) | |
| 1242 | + { | |
| 1243 | + return *this; | |
| 1244 | + } | |
| 1245 | + QPDFObjectHandle result = QPDFObjectHandle::newArray(); | |
| 1246 | + result.appendItem(*this); | |
| 1247 | + return result; | |
| 1248 | +} | |
| 1249 | + | |
| 1250 | +QPDFObjectHandle | |
| 1239 | 1251 | QPDFObjectHandle::parse(std::string const& object_str, |
| 1240 | 1252 | std::string const& object_description) |
| 1241 | 1253 | { | ... | ... |