diff options
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/JSON.cc | 11 | ||||
-rw-r--r-- | libqpdf/QPDFJob.cc | 20 |
2 files changed, 20 insertions, 11 deletions
diff --git a/libqpdf/JSON.cc b/libqpdf/JSON.cc index 31675a42..1c49f9ee 100644 --- a/libqpdf/JSON.cc +++ b/libqpdf/JSON.cc @@ -78,6 +78,14 @@ JSON::writeArrayClose(Pipeline* p, bool first, size_t depth) } void +JSON::writeDictionaryKey( + Pipeline* p, bool& first, std::string const& key, size_t depth) +{ + writeNext(p, first, depth); + *p << "\"" << key << "\": "; +} + +void JSON::writeDictionaryItem( Pipeline* p, bool& first, @@ -85,8 +93,7 @@ JSON::writeDictionaryItem( JSON const& value, size_t depth) { - writeNext(p, first, depth); - *p << "\"" << key << "\": "; + writeDictionaryKey(p, first, key, depth); value.write(p, 1 + depth); } diff --git a/libqpdf/QPDFJob.cc b/libqpdf/QPDFJob.cc index 5621ef5e..63fa0c34 100644 --- a/libqpdf/QPDFJob.cc +++ b/libqpdf/QPDFJob.cc @@ -1044,20 +1044,23 @@ QPDFJob::getWantedJSONObjects() void QPDFJob::doJSONObjects(Pipeline* p, bool& first, QPDF& pdf) { + JSON::writeDictionaryKey(p, first, "objects", 0); + bool first_object = true; + JSON::writeDictionaryOpen(p, first_object, 1); bool all_objects = m->json_objects.empty(); std::set<QPDFObjGen> wanted_og = getWantedJSONObjects(); - JSON j_objects = JSON::makeDictionary(); - if (all_objects || m->json_objects.count("trailer")) { - j_objects.addDictionaryMember( - "trailer", pdf.getTrailer().getJSON(true)); - } std::vector<QPDFObjectHandle> objects = pdf.getAllObjects(); for (auto& obj: objects) { if (all_objects || wanted_og.count(obj.getObjGen())) { - j_objects.addDictionaryMember(obj.unparse(), obj.getJSON(true)); + JSON::writeDictionaryItem( + p, first_object, obj.unparse(), obj.getJSON(true), 1); } } - JSON::writeDictionaryItem(p, first, "objects", j_objects, 0); + if (all_objects || m->json_objects.count("trailer")) { + JSON::writeDictionaryItem( + p, first_object, "trailer", pdf.getTrailer().getJSON(true), 1); + } + JSON::writeDictionaryClose(p, first_object, 1); } void @@ -1090,8 +1093,7 @@ QPDFJob::doJSONObjectinfo(Pipeline* p, bool& first, QPDF& pdf) void QPDFJob::doJSONPages(Pipeline* p, bool& first, QPDF& pdf) { - JSON::writeNext(p, first, 0); - *p << "\"pages\": "; + JSON::writeDictionaryKey(p, first, "pages", 0); bool first_page = true; JSON::writeArrayOpen(p, first_page, 1); QPDFPageDocumentHelper pdh(pdf); |