Commit 0b53b648ab79a35b9ec0da56c0b936955a51d135
1 parent
c2ab0441
Refactor QPDF_Array::unparse
Showing
1 changed file
with
22 additions
and
13 deletions
libqpdf/QPDF_Array.cc
| ... | ... | @@ -128,24 +128,33 @@ QPDF_Array::disconnect() |
| 128 | 128 | std::string |
| 129 | 129 | QPDF_Array::unparse() |
| 130 | 130 | { |
| 131 | + std::string result = "[ "; | |
| 131 | 132 | if (sparse) { |
| 132 | - std::string result = "[ "; | |
| 133 | - for (int i = 0; i < sp_size; ++i) { | |
| 134 | - result += at(i).unparse(); | |
| 135 | - result += " "; | |
| 133 | + int next = 0; | |
| 134 | + for (auto& item: sp_elements) { | |
| 135 | + int key = item.first; | |
| 136 | + for (int j = next; j < key; ++j) { | |
| 137 | + result += "null "; | |
| 138 | + } | |
| 139 | + item.second->resolve(); | |
| 140 | + auto og = item.second->getObjGen(); | |
| 141 | + result += og.isIndirect() ? og.unparse(' ') + " R " | |
| 142 | + : item.second->unparse() + " "; | |
| 143 | + next = ++key; | |
| 144 | + } | |
| 145 | + for (int j = next; j < sp_size; ++j) { | |
| 146 | + result += "null "; | |
| 136 | 147 | } |
| 137 | - result += "]"; | |
| 138 | - return result; | |
| 139 | 148 | } else { |
| 140 | - std::string result = "[ "; | |
| 141 | - auto size = elements.size(); | |
| 142 | - for (int i = 0; i < int(size); ++i) { | |
| 143 | - result += at(i).unparse(); | |
| 144 | - result += " "; | |
| 149 | + for (auto const& item: elements) { | |
| 150 | + item->resolve(); | |
| 151 | + auto og = item->getObjGen(); | |
| 152 | + result += og.isIndirect() ? og.unparse(' ') + " R " | |
| 153 | + : item->unparse() + " "; | |
| 145 | 154 | } |
| 146 | - result += "]"; | |
| 147 | - return result; | |
| 148 | 155 | } |
| 156 | + result += "]"; | |
| 157 | + return result; | |
| 149 | 158 | } |
| 150 | 159 | |
| 151 | 160 | JSON | ... | ... |