mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 07:41:01 +00:00
AK: De-duplicate the definition of the JSON value variant
This commit is contained in:
parent
06faa7b160
commit
a8bc0aed4a
Notes:
github-actions[bot]
2025-02-21 00:29:47 +00:00
Author: https://github.com/trflynn89
Commit: a8bc0aed4a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3631
Reviewed-by: https://github.com/awesomekling ✅
2 changed files with 16 additions and 27 deletions
|
@ -13,28 +13,16 @@
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
|
||||||
namespace {
|
static ErrorOr<JsonValue::Storage> clone(JsonValue::Storage const& other)
|
||||||
using JsonValueStorage = Variant<
|
|
||||||
Empty,
|
|
||||||
bool,
|
|
||||||
i64,
|
|
||||||
u64,
|
|
||||||
double,
|
|
||||||
ByteString,
|
|
||||||
NonnullOwnPtr<JsonArray>,
|
|
||||||
NonnullOwnPtr<JsonObject>>;
|
|
||||||
|
|
||||||
static ErrorOr<JsonValueStorage> clone(JsonValueStorage const& other)
|
|
||||||
{
|
{
|
||||||
return other.visit(
|
return other.visit(
|
||||||
[](NonnullOwnPtr<JsonArray> const& value) -> ErrorOr<JsonValueStorage> {
|
[](NonnullOwnPtr<JsonArray> const& value) -> ErrorOr<JsonValue::Storage> {
|
||||||
return TRY(try_make<JsonArray>(*value));
|
return TRY(try_make<JsonArray>(*value));
|
||||||
},
|
},
|
||||||
[](NonnullOwnPtr<JsonObject> const& value) -> ErrorOr<JsonValueStorage> {
|
[](NonnullOwnPtr<JsonObject> const& value) -> ErrorOr<JsonValue::Storage> {
|
||||||
return TRY(try_make<JsonObject>(*value));
|
return TRY(try_make<JsonObject>(*value));
|
||||||
},
|
},
|
||||||
[](auto const& value) -> ErrorOr<JsonValueStorage> { return JsonValueStorage(value); });
|
[](auto const& value) -> ErrorOr<JsonValue::Storage> { return JsonValue::Storage(value); });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonValue::JsonValue() = default;
|
JsonValue::JsonValue() = default;
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
#include <AK/ByteString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/Forward.h>
|
#include <AK/Forward.h>
|
||||||
|
#include <AK/NonnullOwnPtr.h>
|
||||||
#include <AK/Optional.h>
|
#include <AK/Optional.h>
|
||||||
#include <AK/OwnPtr.h>
|
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
@ -26,6 +26,16 @@ public:
|
||||||
Object,
|
Object,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using Storage = Variant<
|
||||||
|
Empty,
|
||||||
|
bool,
|
||||||
|
i64,
|
||||||
|
u64,
|
||||||
|
double,
|
||||||
|
ByteString,
|
||||||
|
NonnullOwnPtr<JsonArray>,
|
||||||
|
NonnullOwnPtr<JsonObject>>;
|
||||||
|
|
||||||
static ErrorOr<JsonValue> from_string(StringView);
|
static ErrorOr<JsonValue> from_string(StringView);
|
||||||
|
|
||||||
JsonValue();
|
JsonValue();
|
||||||
|
@ -222,16 +232,7 @@ public:
|
||||||
bool equals(JsonValue const& other) const;
|
bool equals(JsonValue const& other) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Variant<
|
Storage m_value;
|
||||||
Empty,
|
|
||||||
bool,
|
|
||||||
i64,
|
|
||||||
u64,
|
|
||||||
double,
|
|
||||||
ByteString,
|
|
||||||
NonnullOwnPtr<JsonArray>,
|
|
||||||
NonnullOwnPtr<JsonObject>>
|
|
||||||
m_value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue