2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 19:08:59 +00:00

Refactor QPDF_Array::unparse

This commit is contained in:
m-holger 2022-12-25 11:03:54 +00:00
parent c2ab0441b5
commit 0b53b648ab

View File

@ -128,24 +128,33 @@ QPDF_Array::disconnect()
std::string std::string
QPDF_Array::unparse() QPDF_Array::unparse()
{ {
std::string result = "[ ";
if (sparse) { if (sparse) {
std::string result = "[ "; int next = 0;
for (int i = 0; i < sp_size; ++i) { for (auto& item: sp_elements) {
result += at(i).unparse(); int key = item.first;
result += " "; 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 { } else {
std::string result = "[ "; for (auto const& item: elements) {
auto size = elements.size(); item->resolve();
for (int i = 0; i < int(size); ++i) { auto og = item->getObjGen();
result += at(i).unparse(); result += og.isIndirect() ? og.unparse(' ') + " R "
result += " "; : item->unparse() + " ";
}
} }
result += "]"; result += "]";
return result; return result;
}
} }
JSON JSON