summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-18 08:55:58 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-18 08:55:58 +0200
commit1a761ea4fdd722309613fcd80a6160c113cc4b2a (patch)
treed6ce505274da05e5d5ecfd66d1f5d9dfe42639c2
parent114768562a1712a4f4f808c03fe22710725e5f50 (diff)
downloadserenity-1a761ea4fdd722309613fcd80a6160c113cc4b2a.zip
AK: Add JsonValue(unsigned) ctor and as_string().
-rw-r--r--AK/JsonValue.cpp11
-rw-r--r--AK/JsonValue.h8
2 files changed, 19 insertions, 0 deletions
diff --git a/AK/JsonValue.cpp b/AK/JsonValue.cpp
index 6b6e10d9a8..1f8aee9afb 100644
--- a/AK/JsonValue.cpp
+++ b/AK/JsonValue.cpp
@@ -65,6 +65,17 @@ JsonValue::JsonValue(int value)
m_value.as_int = value;
}
+JsonValue::JsonValue(unsigned value)
+{
+ if (value > INT32_MAX) {
+ m_type = Type::Double;
+ m_value.as_double = value;
+ } else {
+ m_type = Type::Int;
+ m_value.as_int = (int)value;
+ }
+}
+
JsonValue::JsonValue(double value)
: m_type(Type::Double)
{
diff --git a/AK/JsonValue.h b/AK/JsonValue.h
index 23d96326fe..d738906189 100644
--- a/AK/JsonValue.h
+++ b/AK/JsonValue.h
@@ -31,6 +31,7 @@ public:
JsonValue& operator=(JsonValue&&);
JsonValue(int);
+ JsonValue(unsigned);
JsonValue(double);
JsonValue(bool);
JsonValue(const String&);
@@ -40,6 +41,13 @@ public:
String to_string() const;
void to_string(StringBuilder&) const;
+ String as_string() const
+ {
+ if (m_type == Type::String)
+ return *m_value.as_string;
+ return { };
+ }
+
private:
void clear();
void copy_from(const JsonValue&);