mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:47:35 +00:00
AK: Add JsonValue(unsigned) ctor and as_string().
This commit is contained in:
parent
114768562a
commit
1a761ea4fd
2 changed files with 19 additions and 0 deletions
|
@ -65,6 +65,17 @@ JsonValue::JsonValue(int value)
|
||||||
m_value.as_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)
|
JsonValue::JsonValue(double value)
|
||||||
: m_type(Type::Double)
|
: m_type(Type::Double)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
JsonValue& operator=(JsonValue&&);
|
JsonValue& operator=(JsonValue&&);
|
||||||
|
|
||||||
JsonValue(int);
|
JsonValue(int);
|
||||||
|
JsonValue(unsigned);
|
||||||
JsonValue(double);
|
JsonValue(double);
|
||||||
JsonValue(bool);
|
JsonValue(bool);
|
||||||
JsonValue(const String&);
|
JsonValue(const String&);
|
||||||
|
@ -40,6 +41,13 @@ public:
|
||||||
String to_string() const;
|
String to_string() const;
|
||||||
void to_string(StringBuilder&) const;
|
void to_string(StringBuilder&) const;
|
||||||
|
|
||||||
|
String as_string() const
|
||||||
|
{
|
||||||
|
if (m_type == Type::String)
|
||||||
|
return *m_value.as_string;
|
||||||
|
return { };
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void clear();
|
void clear();
|
||||||
void copy_from(const JsonValue&);
|
void copy_from(const JsonValue&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue