1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 10:01:13 +09:00

AK: Use east const style in Json{Array,Object}.h

This commit is contained in:
Max Wipfli 2021-06-28 10:21:20 +02:00 committed by Andreas Kling
parent 9179a2ea73
commit 53480180cb
Notes: sideshowbarker 2024-07-18 11:21:39 +09:00
2 changed files with 15 additions and 14 deletions

View file

@ -17,7 +17,7 @@ public:
JsonArray() = default; JsonArray() = default;
~JsonArray() = default; ~JsonArray() = default;
JsonArray(const JsonArray& other) JsonArray(JsonArray const& other)
: m_values(other.m_values) : m_values(other.m_values)
{ {
} }
@ -28,13 +28,13 @@ public:
} }
template<typename T> template<typename T>
JsonArray(const Vector<T>& vector) JsonArray(Vector<T> const& vector)
{ {
for (auto& value : vector) for (auto& value : vector)
m_values.append(move(value)); m_values.append(move(value));
} }
JsonArray& operator=(const JsonArray& other) JsonArray& operator=(JsonArray const& other)
{ {
if (this != &other) if (this != &other)
m_values = other.m_values; m_values = other.m_values;
@ -51,8 +51,8 @@ public:
int size() const { return m_values.size(); } int size() const { return m_values.size(); }
bool is_empty() const { return m_values.is_empty(); } bool is_empty() const { return m_values.is_empty(); }
const JsonValue& at(size_t index) const { return m_values.at(index); } JsonValue const& at(size_t index) const { return m_values.at(index); }
const JsonValue& operator[](size_t index) const { return at(index); } JsonValue const& operator[](size_t index) const { return at(index); }
void clear() { m_values.clear(); } void clear() { m_values.clear(); }
void append(JsonValue value) { m_values.append(move(value)); } void append(JsonValue value) { m_values.append(move(value)); }
@ -73,7 +73,7 @@ public:
callback(value); callback(value);
} }
const Vector<JsonValue>& values() const { return m_values; } Vector<JsonValue> const& values() const { return m_values; }
void ensure_capacity(int capacity) { m_values.ensure_capacity(capacity); } void ensure_capacity(int capacity) { m_values.ensure_capacity(capacity); }

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Max Wipfli <mail@maxwipfli.ch>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -19,7 +20,7 @@ public:
JsonObject() = default; JsonObject() = default;
~JsonObject() = default; ~JsonObject() = default;
JsonObject(const JsonObject& other) JsonObject(JsonObject const& other)
: m_order(other.m_order) : m_order(other.m_order)
, m_members(other.m_members) , m_members(other.m_members)
{ {
@ -31,7 +32,7 @@ public:
{ {
} }
JsonObject& operator=(const JsonObject& other) JsonObject& operator=(JsonObject const& other)
{ {
if (this != &other) { if (this != &other) {
m_members = other.m_members; m_members = other.m_members;
@ -52,19 +53,19 @@ public:
int size() const { return m_members.size(); } int size() const { return m_members.size(); }
bool is_empty() const { return m_members.is_empty(); } bool is_empty() const { return m_members.is_empty(); }
JsonValue get(const String& key) const JsonValue get(String const& key) const
{ {
auto* value = get_ptr(key); auto* value = get_ptr(key);
return value ? *value : JsonValue(JsonValue::Type::Null); return value ? *value : JsonValue(JsonValue::Type::Null);
} }
JsonValue get_or(const String& key, const JsonValue& alternative) const JsonValue get_or(String const& key, JsonValue const& alternative) const
{ {
auto* value = get_ptr(key); auto* value = get_ptr(key);
return value ? *value : alternative; return value ? *value : alternative;
} }
const JsonValue* get_ptr(const String& key) const JsonValue const* get_ptr(String const& key) const
{ {
auto it = m_members.find(key); auto it = m_members.find(key);
if (it == m_members.end()) if (it == m_members.end())
@ -72,12 +73,12 @@ public:
return &(*it).value; return &(*it).value;
} }
bool has(const String& key) const bool has(String const& key) const
{ {
return m_members.contains(key); return m_members.contains(key);
} }
void set(const String& key, JsonValue value) void set(String const& key, JsonValue value)
{ {
if (m_members.set(key, move(value)) == HashSetResult::ReplacedExistingEntry) if (m_members.set(key, move(value)) == HashSetResult::ReplacedExistingEntry)
m_order.remove(m_order.find_first_index(key).value()); m_order.remove(m_order.find_first_index(key).value());
@ -93,7 +94,7 @@ public:
} }
} }
bool remove(const String& key) bool remove(String const& key)
{ {
if (m_members.remove(key)) { if (m_members.remove(key)) {
m_order.remove(m_order.find_first_index(key).value()); m_order.remove(m_order.find_first_index(key).value());