aboutsummaryrefslogtreecommitdiffstats
path: root/include/qpdf/JSON.hh
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-05-07 01:04:20 +0200
committerJay Berkenbilt <ejb@ql.org>2022-05-07 14:26:31 +0200
commit948de609900745835656d4566a90fee64c5343da (patch)
treee4862655453cc6213f2a1713fc1548462a38a8df /include/qpdf/JSON.hh
parentf50274ef4660cb21177937ff49c9d11675cef8a9 (diff)
downloadqpdf-948de609900745835656d4566a90fee64c5343da.tar.zst
Objects json: write incrementally and in numeric order
The following script was used to adjust test data: ---------- #!/usr/bin/env python3 import json import sys import re def json_dumps(data): return json.dumps(data, ensure_ascii=False, indent=2, separators=(',', ': ')) for filename in sys.argv[1:]: with open(filename, 'r') as f: data = json.loads(f.read()) if 'objects' not in data: continue trailer = None to_sort = [] for k, v in data['objects'].items(): if k == 'trailer': trailer = v else: m = re.match(r'^(\d+) \d+ R', k) if m: to_sort.append([int(m.group(1)), k, v]) newobjects = {x[1]: x[2] for x in sorted(to_sort)} if trailer is not None: newobjects['trailer'] = trailer data['objects'] = newobjects print(json_dumps(data)) ----------
Diffstat (limited to 'include/qpdf/JSON.hh')
-rw-r--r--include/qpdf/JSON.hh7
1 files changed, 6 insertions, 1 deletions
diff --git a/include/qpdf/JSON.hh b/include/qpdf/JSON.hh
index a1a61ee4..fdacd442 100644
--- a/include/qpdf/JSON.hh
+++ b/include/qpdf/JSON.hh
@@ -92,6 +92,11 @@ class JSON
std::string const& key,
JSON const& value,
size_t depth = 0);
+ // Write just the key of a new dictionary item, useful if writing
+ // nested structures. Calls writeNext.
+ QPDF_DLL
+ static void writeDictionaryKey(
+ Pipeline* p, bool& first, std::string const& key, size_t depth = 0);
QPDF_DLL
static void writeArrayItem(
Pipeline*, bool& first, JSON const& element, size_t depth = 0);
@@ -101,7 +106,7 @@ class JSON
// for the parent object. Then start a new first for the nested
// item.
QPDF_DLL
- static void writeNext(Pipeline* p, bool& first, size_t depth);
+ static void writeNext(Pipeline* p, bool& first, size_t depth = 0);
// The JSON spec calls dictionaries "objects", but that creates
// too much confusion when referring to instances of the JSON