summaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2022-12-25 12:03:54 +0100
committerm-holger <m-holger@kubitscheck.org>2023-04-01 14:58:21 +0200
commit0b53b648ab79a35b9ec0da56c0b936955a51d135 (patch)
tree4c5e864c92d70e91256fed0238ac8ea53f872a9c /libqpdf
parentc2ab0441b5d2c03a732d68e2ed36a19343ccbb5a (diff)
downloadqpdf-0b53b648ab79a35b9ec0da56c0b936955a51d135.tar.zst
Refactor QPDF_Array::unparse
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/QPDF_Array.cc35
1 files changed, 22 insertions, 13 deletions
diff --git a/libqpdf/QPDF_Array.cc b/libqpdf/QPDF_Array.cc
index 2cb4bce5..3bd139b1 100644
--- a/libqpdf/QPDF_Array.cc
+++ b/libqpdf/QPDF_Array.cc
@@ -128,24 +128,33 @@ QPDF_Array::disconnect()
std::string
QPDF_Array::unparse()
{
+ std::string result = "[ ";
if (sparse) {
- std::string result = "[ ";
- for (int i = 0; i < sp_size; ++i) {
- result += at(i).unparse();
- result += " ";
+ int next = 0;
+ for (auto& item: sp_elements) {
+ int key = item.first;
+ for (int j = next; j < key; ++j) {
+ result += "null ";
+ }
+ item.second->resolve();
+ auto og = item.second->getObjGen();
+ result += og.isIndirect() ? og.unparse(' ') + " R "
+ : item.second->unparse() + " ";
+ next = ++key;
+ }
+ for (int j = next; j < sp_size; ++j) {
+ result += "null ";
}
- result += "]";
- return result;
} else {
- std::string result = "[ ";
- auto size = elements.size();
- for (int i = 0; i < int(size); ++i) {
- result += at(i).unparse();
- result += " ";
+ for (auto const& item: elements) {
+ item->resolve();
+ auto og = item->getObjGen();
+ result += og.isIndirect() ? og.unparse(' ') + " R "
+ : item->unparse() + " ";
}
- result += "]";
- return result;
}
+ result += "]";
+ return result;
}
JSON