From 0b53b648ab79a35b9ec0da56c0b936955a51d135 Mon Sep 17 00:00:00 2001 From: m-holger Date: Sun, 25 Dec 2022 11:03:54 +0000 Subject: Refactor QPDF_Array::unparse --- libqpdf/QPDF_Array.cc | 35 ++++++++++++++++++++++------------- 1 file 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 -- cgit v1.2.3-54-g00ecf