From c5bbd7befd79eaa6bf0e48a6f4b8a404231c5231 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Fri, 8 Jul 2022 14:11:03 +0200 Subject: [PATCH] Util: Add exists() to Json::Value --- src/util/json/value.cpp | 11 +++++++++++ src/util/json/value.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/util/json/value.cpp b/src/util/json/value.cpp index b535bc0..8b5d9fa 100644 --- a/src/util/json/value.cpp +++ b/src/util/json/value.cpp @@ -146,6 +146,17 @@ void Value::emplace(const std::string& key, Value value) m_value.asObject->emplace(key, value); } +bool Value::exists(size_t index) const +{ + return index < size(); +} + +bool Value::exists(const std::string& key) const +{ + assert(m_type == Type::Object); + return m_value.asObject->members().find(key) != m_value.asObject->members().end(); +} + // ------------------------------------------ Value& Value::operator[](size_t index) diff --git a/src/util/json/value.h b/src/util/json/value.h index a7c8bf9..93481b2 100644 --- a/src/util/json/value.h +++ b/src/util/json/value.h @@ -55,6 +55,9 @@ public: void emplace_back(Value value); void emplace(const std::string& key, Value value); + bool exists(size_t index) const; + bool exists(const std::string& key) const; + // -------------------------------------- // Array index operator