From 08de9eeaca3b1b757586f32ff1932a62322f17e5 Mon Sep 17 00:00:00 2001 From: garethsb-sony Date: Mon, 25 Feb 2019 09:10:45 +0000 Subject: [PATCH] Add json_pointer::parent_pointer (cf. std::filesystem::path::parent_path) --- include/nlohmann/detail/json_pointer.hpp | 15 +++++++++++++++ single_include/nlohmann/json.hpp | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/nlohmann/detail/json_pointer.hpp b/include/nlohmann/detail/json_pointer.hpp index 1efb5049..28a7e8f3 100644 --- a/include/nlohmann/detail/json_pointer.hpp +++ b/include/nlohmann/detail/json_pointer.hpp @@ -122,6 +122,21 @@ class json_pointer return json_pointer(lhs) /= array_index; } + /*! + @brief create a new JSON pointer that is the parent of this JSON pointer + */ + json_pointer parent_pointer() const + { + if (empty()) + { + return *this; + } + + json_pointer res = *this; + res.pop_back(); + return res; + } + /*! @param[in] s reference token to be converted into an array index diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index f3688a1c..15ec3b86 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -11932,6 +11932,21 @@ class json_pointer return json_pointer(lhs) /= array_index; } + /*! + @brief create a new JSON pointer that is the parent of this JSON pointer + */ + json_pointer parent_pointer() const + { + if (empty()) + { + return *this; + } + + json_pointer res = *this; + res.pop_back(); + return res; + } + /*! @param[in] s reference token to be converted into an array index