mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +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: https://github.com/LadybirdBrowser/ladybird/commit/a8bc0aed4ab 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 {
|
||||
using JsonValueStorage = Variant<
|
||||
Empty,
|
||||
bool,
|
||||
i64,
|
||||
u64,
|
||||
double,
|
||||
ByteString,
|
||||
NonnullOwnPtr<JsonArray>,
|
||||
NonnullOwnPtr<JsonObject>>;
|
||||
|
||||
static ErrorOr<JsonValueStorage> clone(JsonValueStorage const& other)
|
||||
static ErrorOr<JsonValue::Storage> clone(JsonValue::Storage const& other)
|
||||
{
|
||||
return other.visit(
|
||||
[](NonnullOwnPtr<JsonArray> const& value) -> ErrorOr<JsonValueStorage> {
|
||||
[](NonnullOwnPtr<JsonArray> const& value) -> ErrorOr<JsonValue::Storage> {
|
||||
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));
|
||||
},
|
||||
[](auto const& value) -> ErrorOr<JsonValueStorage> { return JsonValueStorage(value); });
|
||||
}
|
||||
[](auto const& value) -> ErrorOr<JsonValue::Storage> { return JsonValue::Storage(value); });
|
||||
}
|
||||
|
||||
JsonValue::JsonValue() = default;
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
#include <AK/ByteString.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
|
||||
namespace AK {
|
||||
|
@ -26,6 +26,16 @@ public:
|
|||
Object,
|
||||
};
|
||||
|
||||
using Storage = Variant<
|
||||
Empty,
|
||||
bool,
|
||||
i64,
|
||||
u64,
|
||||
double,
|
||||
ByteString,
|
||||
NonnullOwnPtr<JsonArray>,
|
||||
NonnullOwnPtr<JsonObject>>;
|
||||
|
||||
static ErrorOr<JsonValue> from_string(StringView);
|
||||
|
||||
JsonValue();
|
||||
|
@ -222,16 +232,7 @@ public:
|
|||
bool equals(JsonValue const& other) const;
|
||||
|
||||
private:
|
||||
Variant<
|
||||
Empty,
|
||||
bool,
|
||||
i64,
|
||||
u64,
|
||||
double,
|
||||
ByteString,
|
||||
NonnullOwnPtr<JsonArray>,
|
||||
NonnullOwnPtr<JsonObject>>
|
||||
m_value;
|
||||
Storage m_value;
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
Loading…
Add table
Reference in a new issue