mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-17 06:52:23 +00:00
AK: Remove unused JsonPath class
This commit is contained in:
parent
7f5e960b72
commit
d8f2a885f9
Notes:
sideshowbarker
2024-07-17 11:30:54 +09:00
Author: https://github.com/awesomekling
Commit: d8f2a885f9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/197
Reviewed-by: https://github.com/ADKaster
4 changed files with 0 additions and 150 deletions
|
@ -15,7 +15,6 @@ set(AK_SOURCES
|
||||||
Hex.cpp
|
Hex.cpp
|
||||||
JsonObject.cpp
|
JsonObject.cpp
|
||||||
JsonParser.cpp
|
JsonParser.cpp
|
||||||
JsonPath.cpp
|
|
||||||
JsonValue.cpp
|
JsonValue.cpp
|
||||||
LexicalPath.cpp
|
LexicalPath.cpp
|
||||||
MemoryStream.cpp
|
MemoryStream.cpp
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020, the SerenityOS developers.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <AK/JsonObject.h>
|
|
||||||
#include <AK/JsonPath.h>
|
|
||||||
#include <AK/JsonValue.h>
|
|
||||||
|
|
||||||
namespace AK {
|
|
||||||
|
|
||||||
JsonPathElement JsonPathElement::any_array_element { Kind::AnyIndex };
|
|
||||||
JsonPathElement JsonPathElement::any_object_element { Kind::AnyKey };
|
|
||||||
|
|
||||||
JsonValue JsonPath::resolve(JsonValue const& top_root) const
|
|
||||||
{
|
|
||||||
auto root = top_root;
|
|
||||||
for (auto const& element : *this) {
|
|
||||||
switch (element.kind()) {
|
|
||||||
case JsonPathElement::Kind::Key:
|
|
||||||
root = JsonValue { root.as_object().get(element.key()).value() };
|
|
||||||
break;
|
|
||||||
case JsonPathElement::Kind::Index:
|
|
||||||
root = JsonValue { root.as_array().at(element.index()) };
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
ByteString JsonPath::to_byte_string() const
|
|
||||||
{
|
|
||||||
StringBuilder builder;
|
|
||||||
builder.append("{ ."sv);
|
|
||||||
for (auto const& el : *this) {
|
|
||||||
builder.append("sv > "sv);
|
|
||||||
builder.append(el.to_byte_string());
|
|
||||||
}
|
|
||||||
builder.append("sv }"sv);
|
|
||||||
return builder.to_byte_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
101
AK/JsonPath.h
101
AK/JsonPath.h
|
@ -1,101 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020, the SerenityOS developers.
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <AK/ByteString.h>
|
|
||||||
#include <AK/Types.h>
|
|
||||||
#include <AK/Vector.h>
|
|
||||||
|
|
||||||
namespace AK {
|
|
||||||
|
|
||||||
class JsonPathElement {
|
|
||||||
public:
|
|
||||||
enum class Kind {
|
|
||||||
Key,
|
|
||||||
Index,
|
|
||||||
AnyIndex,
|
|
||||||
AnyKey,
|
|
||||||
};
|
|
||||||
|
|
||||||
JsonPathElement(size_t index)
|
|
||||||
: m_kind(Kind::Index)
|
|
||||||
, m_index(index)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonPathElement(StringView key)
|
|
||||||
: m_kind(Kind::Key)
|
|
||||||
, m_key(key)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Kind kind() const { return m_kind; }
|
|
||||||
ByteString const& key() const
|
|
||||||
{
|
|
||||||
VERIFY(m_kind == Kind::Key);
|
|
||||||
return m_key;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t index() const
|
|
||||||
{
|
|
||||||
VERIFY(m_kind == Kind::Index);
|
|
||||||
return m_index;
|
|
||||||
}
|
|
||||||
|
|
||||||
ByteString to_byte_string() const
|
|
||||||
{
|
|
||||||
switch (m_kind) {
|
|
||||||
case Kind::Key:
|
|
||||||
return key();
|
|
||||||
case Kind::Index:
|
|
||||||
return ByteString::number(index());
|
|
||||||
default:
|
|
||||||
return "*";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static JsonPathElement any_array_element;
|
|
||||||
static JsonPathElement any_object_element;
|
|
||||||
|
|
||||||
bool operator==(JsonPathElement const& other) const
|
|
||||||
{
|
|
||||||
switch (other.kind()) {
|
|
||||||
case Kind::Key:
|
|
||||||
return (m_kind == Kind::Key && other.key() == key()) || m_kind == Kind::AnyKey;
|
|
||||||
case Kind::Index:
|
|
||||||
return (m_kind == Kind::Index && other.index() == index()) || m_kind == Kind::AnyIndex;
|
|
||||||
case Kind::AnyKey:
|
|
||||||
return m_kind == Kind::Key;
|
|
||||||
case Kind::AnyIndex:
|
|
||||||
return m_kind == Kind::Index;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Kind m_kind;
|
|
||||||
ByteString m_key;
|
|
||||||
size_t m_index { 0 };
|
|
||||||
|
|
||||||
JsonPathElement(Kind kind)
|
|
||||||
: m_kind(kind)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class JsonPath : public Vector<JsonPathElement> {
|
|
||||||
public:
|
|
||||||
JsonValue resolve(JsonValue const&) const;
|
|
||||||
ByteString to_byte_string() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#if USING_AK_GLOBALLY
|
|
||||||
using AK::JsonPath;
|
|
||||||
using AK::JsonPathElement;
|
|
||||||
#endif
|
|
|
@ -105,8 +105,6 @@ shared_library("AK") {
|
||||||
"JsonObjectSerializer.h",
|
"JsonObjectSerializer.h",
|
||||||
"JsonParser.cpp",
|
"JsonParser.cpp",
|
||||||
"JsonParser.h",
|
"JsonParser.h",
|
||||||
"JsonPath.cpp",
|
|
||||||
"JsonPath.h",
|
|
||||||
"JsonValue.cpp",
|
"JsonValue.cpp",
|
||||||
"JsonValue.h",
|
"JsonValue.h",
|
||||||
"LEB128.h",
|
"LEB128.h",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue