mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Add get_or() method to JsonObject
This allows to retrieve a default value for items thare are not available in the json object.
This commit is contained in:
parent
5f579904c1
commit
45921328e4
Notes:
sideshowbarker
2024-07-19 08:08:46 +09:00
Author: https://github.com/lnzero1dev Commit: https://github.com/SerenityOS/serenity/commit/45921328e49 Pull-request: https://github.com/SerenityOS/serenity/pull/1510
1 changed files with 6 additions and 0 deletions
|
@ -72,6 +72,12 @@ public:
|
|||
return value ? *value : JsonValue(JsonValue::Type::Undefined);
|
||||
}
|
||||
|
||||
JsonValue get_or(const String& key, JsonValue alternative) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value ? *value : alternative;
|
||||
}
|
||||
|
||||
const JsonValue* get_ptr(const String& key) const
|
||||
{
|
||||
auto it = m_members.find(key);
|
||||
|
|
Loading…
Reference in a new issue