From c5d623e04847d06ae4ee5c9bcc441ab80e4f6b8f Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 19 Jun 2019 13:08:07 +0200 Subject: [PATCH] AK: Add some convenient functions to JsonValue. --- AK/JsonValue.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/AK/JsonValue.h b/AK/JsonValue.h index 50ddcf49c6..211086d2d1 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -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&);