AK: Add JsonObject::get_ptr() for copy-free lookup

This variant of get() returns a const JsonValue* instead of a JsonValue
and can be used when you want to peek into a JsonObject's member fields
without making copies.
This commit is contained in:
Andreas Kling 2019-12-30 14:49:45 +01:00
parent b0bbdc53e9
commit 7011dba98e

View file

@ -41,11 +41,17 @@ public:
bool is_empty() const { return m_members.is_empty(); }
JsonValue get(const String& key) const
{
auto* value = get_ptr(key);
return value ? *value : JsonValue(JsonValue::Type::Undefined);
}
const JsonValue* get_ptr(const String& key) const
{
auto it = m_members.find(key);
if (it == m_members.end())
return JsonValue(JsonValue::Type::Undefined);
return (*it).value;
return nullptr;
return &(*it).value;
}
bool has(const String& key) const