From d8f2a885f9e9802899ca40abe36764fb0cd99936 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 18 Jun 2024 09:48:00 +0200 Subject: [PATCH] AK: Remove unused JsonPath class --- AK/CMakeLists.txt | 1 - AK/JsonPath.cpp | 46 ---------------- AK/JsonPath.h | 101 ---------------------------------- Meta/gn/secondary/AK/BUILD.gn | 2 - 4 files changed, 150 deletions(-) delete mode 100644 AK/JsonPath.cpp delete mode 100644 AK/JsonPath.h diff --git a/AK/CMakeLists.txt b/AK/CMakeLists.txt index 101c8d9f327..411b2833cd9 100644 --- a/AK/CMakeLists.txt +++ b/AK/CMakeLists.txt @@ -15,7 +15,6 @@ set(AK_SOURCES Hex.cpp JsonObject.cpp JsonParser.cpp - JsonPath.cpp JsonValue.cpp LexicalPath.cpp MemoryStream.cpp diff --git a/AK/JsonPath.cpp b/AK/JsonPath.cpp deleted file mode 100644 index b761757a277..00000000000 --- a/AK/JsonPath.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2020, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include - -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(); -} - -} diff --git a/AK/JsonPath.h b/AK/JsonPath.h deleted file mode 100644 index f24f91684b3..00000000000 --- a/AK/JsonPath.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2020, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include - -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 { -public: - JsonValue resolve(JsonValue const&) const; - ByteString to_byte_string() const; -}; - -} - -#if USING_AK_GLOBALLY -using AK::JsonPath; -using AK::JsonPathElement; -#endif diff --git a/Meta/gn/secondary/AK/BUILD.gn b/Meta/gn/secondary/AK/BUILD.gn index d67ebe95ace..1e914107395 100644 --- a/Meta/gn/secondary/AK/BUILD.gn +++ b/Meta/gn/secondary/AK/BUILD.gn @@ -105,8 +105,6 @@ shared_library("AK") { "JsonObjectSerializer.h", "JsonParser.cpp", "JsonParser.h", - "JsonPath.cpp", - "JsonPath.h", "JsonValue.cpp", "JsonValue.h", "LEB128.h",