From 293946c960152ba3d98ab93c8829bf1f1e017f67 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 29 Jun 2019 12:04:36 +0200 Subject: [PATCH] JsonValue: Add is_bool() and various as_foo() helpers. --- AK/JsonValue.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/AK/JsonValue.h b/AK/JsonValue.h index 201a69c7c6..706c39962b 100644 --- a/AK/JsonValue.h +++ b/AK/JsonValue.h @@ -57,6 +57,24 @@ public: return default_value; } + int as_int() const + { + ASSERT(is_int()); + return m_value.as_int; + } + + int as_uint() const + { + ASSERT(is_uint()); + return m_value.as_uint; + } + + int as_bool() const + { + ASSERT(is_bool()); + return m_value.as_bool; + } + String as_string() const { ASSERT(is_string()); @@ -79,6 +97,7 @@ public: bool is_null() const { return m_type == Type::Null; } bool is_undefined() const { return m_type == Type::Undefined; } + bool is_bool() const { return m_type == Type::Bool; } bool is_string() const { return m_type == Type::String; } bool is_int() const { return m_type == Type::Int; } bool is_uint() const { return m_type == Type::UnsignedInt; }