mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-02-17 05:06:46 +00:00
AK: Add JsonObject::has_* methods
This adds methods to JsonObject to check if a key exists with a certain type. This simplifies code that validates whether a JsonObject has the expected structure.
This commit is contained in:
committed by
Andreas Kling
parent
f45273649f
commit
e82611bb87
@@ -78,6 +78,64 @@ public:
|
||||
return m_members.contains(key);
|
||||
}
|
||||
|
||||
bool has_null(String const& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value && value->is_null();
|
||||
}
|
||||
bool has_bool(String const& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value && value->is_bool();
|
||||
}
|
||||
bool has_string(String const& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value && value->is_string();
|
||||
}
|
||||
bool has_i32(String const& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value && value->is_i32();
|
||||
}
|
||||
bool has_u32(String const& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value && value->is_u32();
|
||||
}
|
||||
bool has_i64(String const& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value && value->is_i64();
|
||||
}
|
||||
bool has_u64(String const& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value && value->is_u64();
|
||||
}
|
||||
bool has_number(String const& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value && value->is_number();
|
||||
}
|
||||
bool has_array(String const& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value && value->is_array();
|
||||
}
|
||||
bool has_object(String const& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value && value->is_object();
|
||||
}
|
||||
#ifndef KERNEL
|
||||
bool has_double(String const& key) const
|
||||
{
|
||||
auto* value = get_ptr(key);
|
||||
return value && value->is_double();
|
||||
}
|
||||
#endif
|
||||
|
||||
void set(String const& key, JsonValue value)
|
||||
{
|
||||
m_members.set(key, move(value));
|
||||
|
||||
Reference in New Issue
Block a user