aboutsummaryrefslogtreecommitdiffstats
path: root/include/qpdf/JSON.hh
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-01-19 15:31:28 +0100
committerJay Berkenbilt <ejb@ql.org>2022-01-30 19:11:03 +0100
commit37105710ee0b332a3020d4b3220c95b8f4267555 (patch)
treeee4b520b1c141033ba16ba3696def57fc90f60fa /include/qpdf/JSON.hh
parenta6df6fdaf724ed5fc6f7e8c021f7804bd5a9c0e2 (diff)
downloadqpdf-37105710ee0b332a3020d4b3220c95b8f4267555.tar.zst
Implement JSONHandler for recursively processing JSON
Diffstat (limited to 'include/qpdf/JSON.hh')
-rw-r--r--include/qpdf/JSON.hh25
1 files changed, 24 insertions, 1 deletions
diff --git a/include/qpdf/JSON.hh b/include/qpdf/JSON.hh
index 676becbf..3b13b4fe 100644
--- a/include/qpdf/JSON.hh
+++ b/include/qpdf/JSON.hh
@@ -30,7 +30,10 @@
// create temporary JSON objects on the stack, add them to other
// objects, and let them go out of scope safely. It also means that if
// the json JSON object is added in more than one place, all copies
-// share underlying data.
+// share underlying data. This makes them similar in structure and
+// behavior to QPDFObjectHandle and may feel natural within the QPDF
+// codebase, but it is also a good reason not to use this as a
+// general-purpose JSON package.
#include <qpdf/DLL.h>
#include <qpdf/PointerHolder.hh>
@@ -38,6 +41,7 @@
#include <map>
#include <vector>
#include <list>
+#include <functional>
class JSON
{
@@ -77,6 +81,24 @@ class JSON
QPDF_DLL
bool isDictionary() const;
+ // Accessors. Accessor behavior:
+ //
+ // - If argument is wrong type, including null, return false
+ // - If argument is right type, return true and initialize the value
+ QPDF_DLL
+ bool getString(std::string& utf8) const;
+ QPDF_DLL
+ bool getNumber(std::string& value) const;
+ QPDF_DLL
+ bool getBool(bool& value) const;
+ QPDF_DLL
+ bool isNull() const;
+ QPDF_DLL
+ bool forEachDictItem(
+ std::function<void(std::string const& key, JSON value)> fn) const;
+ QPDF_DLL
+ bool forEachArrayItem(std::function<void(JSON value)> fn) const;
+
// Check this JSON object against a "schema". This is not a schema
// according to any standard. It's just a template of what the
// JSON is supposed to contain. The checking does the following:
@@ -129,6 +151,7 @@ class JSON
JSON_string(std::string const& utf8);
virtual ~JSON_string();
virtual std::string unparse(size_t depth) const;
+ std::string utf8;
std::string encoded;
};
struct JSON_number: public JSON_value