blob: e55c2eea0d58ec51879c5616b6c32616c0d45304 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Max Wipfli <mail@maxwipfli.ch>
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "JsonObject.h"
namespace AK {
JsonObject::JsonObject() = default;
JsonObject::~JsonObject() = default;
JsonObject::JsonObject(JsonObject const& other)
: m_members(other.m_members)
{
}
JsonObject::JsonObject(JsonObject&& other)
: m_members(move(other.m_members))
{
}
JsonObject& JsonObject::operator=(JsonObject const& other)
{
if (this != &other)
m_members = other.m_members;
return *this;
}
JsonObject& JsonObject::operator=(JsonObject&& other)
{
if (this != &other)
m_members = move(other.m_members);
return *this;
}
size_t JsonObject::size() const
{
return m_members.size();
}
bool JsonObject::is_empty() const
{
return m_members.is_empty();
}
JsonValue const& JsonObject::get_deprecated(StringView key) const
{
auto const* value = get_ptr(key);
static JsonValue* s_null_value { nullptr };
if (!value) {
if (!s_null_value)
s_null_value = new JsonValue;
return *s_null_value;
}
return *value;
}
JsonValue const* JsonObject::get_ptr(StringView key) const
{
auto it = m_members.find(key);
if (it == m_members.end())
return nullptr;
return &(*it).value;
}
bool JsonObject::has(StringView key) const
{
return m_members.contains(key);
}
bool JsonObject::has_null(StringView key) const
{
auto const* value = get_ptr(key);
return value && value->is_null();
}
bool JsonObject::has_bool(StringView key) const
{
auto const* value = get_ptr(key);
return value && value->is_bool();
}
bool JsonObject::has_string(StringView key) const
{
auto const* value = get_ptr(key);
return value && value->is_string();
}
bool JsonObject::has_i32(StringView key) const
{
auto const* value = get_ptr(key);
return value && value->is_i32();
}
bool JsonObject::has_u32(StringView key) const
{
auto const* value = get_ptr(key);
return value && value->is_u32();
}
bool JsonObject::has_i64(StringView key) const
{
auto const* value = get_ptr(key);
return value && value->is_i64();
}
bool JsonObject::has_u64(StringView key) const
{
auto const* value = get_ptr(key);
return value && value->is_u64();
}
bool JsonObject::has_number(StringView key) const
{
auto const* value = get_ptr(key);
return value && value->is_number();
}
bool JsonObject::has_array(StringView key) const
{
auto const* value = get_ptr(key);
return value && value->is_array();
}
bool JsonObject::has_object(StringView key) const
{
auto const* value = get_ptr(key);
return value && value->is_object();
}
#ifndef KERNEL
bool JsonObject::has_double(StringView key) const
{
auto const* value = get_ptr(key);
return value && value->is_double();
}
#endif
void JsonObject::set(DeprecatedString const& key, JsonValue value)
{
m_members.set(key, move(value));
}
bool JsonObject::remove(StringView key)
{
return m_members.remove(key);
}
DeprecatedString JsonObject::to_deprecated_string() const
{
return serialized<StringBuilder>();
}
}
|