mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Add some convenient functions to JsonValue.
This commit is contained in:
parent
9149a519f5
commit
c5d623e048
Notes:
sideshowbarker
2024-07-19 13:32:54 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/c5d623e0484
1 changed files with 20 additions and 0 deletions
|
@ -49,6 +49,26 @@ public:
|
|||
return { };
|
||||
}
|
||||
|
||||
Type type() const { return m_type; }
|
||||
|
||||
bool is_null() const { return m_type == Type::Null; }
|
||||
bool is_undefined() const { return m_type == Type::Undefined; }
|
||||
bool is_string() const { return m_type == Type::String; }
|
||||
bool is_int() const { return m_type == Type::Int; }
|
||||
bool is_double() const { return m_type == Type::Double; }
|
||||
bool is_array() const { return m_type == Type::Array; }
|
||||
bool is_object() const { return m_type == Type::Object; }
|
||||
bool is_number() const { return m_type == Type::Int || m_type == Type::Double; }
|
||||
|
||||
dword to_dword(dword default_value = 0) const
|
||||
{
|
||||
if (!is_number())
|
||||
return default_value;
|
||||
if (type() == Type::Int)
|
||||
return (dword)m_value.as_int;
|
||||
return (dword)m_value.as_double;
|
||||
}
|
||||
|
||||
private:
|
||||
void clear();
|
||||
void copy_from(const JsonValue&);
|
||||
|
|
Loading…
Reference in a new issue