mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Add new method JSON::getDictItem
This commit is contained in:
parent
7315aa8c9b
commit
a41b789995
@ -162,6 +162,8 @@ class JSON
|
||||
QPDF_DLL
|
||||
bool isNull() const;
|
||||
QPDF_DLL
|
||||
JSON getDictItem(std::string const& key) 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;
|
||||
|
@ -410,6 +410,17 @@ JSON::isNull() const
|
||||
return m->value->type_code == vt_null;
|
||||
}
|
||||
|
||||
JSON
|
||||
JSON::getDictItem(std::string const& key) const
|
||||
{
|
||||
if (auto v = dynamic_cast<JSON_dictionary const*>(m->value.get())) {
|
||||
if (auto it = v->members.find(key); it != v->members.end()) {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
return makeNull();
|
||||
}
|
||||
|
||||
bool
|
||||
JSON::forEachDictItem(std::function<void(std::string const& key, JSON value)> fn) const
|
||||
{
|
||||
|
@ -78,6 +78,12 @@ test_main()
|
||||
jmap.addDictionaryMember("empty_dict", JSON::makeDictionary());
|
||||
jmap.addDictionaryMember("empty_list", JSON::makeArray());
|
||||
jmap.addDictionaryMember("single", JSON::makeArray()).addArrayElement(JSON::makeInt(12));
|
||||
std::string jm_str;
|
||||
assert(jmap.getDictItem("b").getString(jm_str));
|
||||
assert(!jmap.getDictItem("b2").getString(jm_str));
|
||||
assert(!jstr2.getDictItem("b").getString(jm_str));
|
||||
assert(jm_str == "a\tb");
|
||||
|
||||
check(
|
||||
jmap,
|
||||
"{\n"
|
||||
|
Loading…
Reference in New Issue
Block a user