mirror of
https://github.com/nlohmann/json.git
synced 2026-05-13 09:45:24 +00:00
* Added front, pop_front, and push_front methods to json_pointers in order to facilitate root-to-leaf traversals of JSON object trees. (#4889) Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com> * undid VS autoformatting in irrelevant code Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com> * Ran make amalgamate, added navigation to json_pointer's new front methods in mkdocs, and fixed errors in documented complexity for those methods. Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com> * Fixed GCC 4.8 compile error caused by const iterators Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com> * Fixed another gcc-4.8 compile error Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com> * amalgamated Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com> --------- Signed-off-by: trdesilva <5818730+trdesilva@users.noreply.github.com>
This commit is contained in:
@@ -154,6 +154,44 @@ class json_pointer
|
||||
return res;
|
||||
}
|
||||
|
||||
/// @brief remove first reference token
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/pop_front/
|
||||
void pop_front()
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||
{
|
||||
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", nullptr));
|
||||
}
|
||||
|
||||
reference_tokens.erase(reference_tokens.begin());
|
||||
}
|
||||
|
||||
/// @brief return first reference token
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/front/
|
||||
const string_t& front() const
|
||||
{
|
||||
if (JSON_HEDLEY_UNLIKELY(empty()))
|
||||
{
|
||||
JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", nullptr));
|
||||
}
|
||||
|
||||
return reference_tokens.front();
|
||||
}
|
||||
|
||||
/// @brief append an unescaped token at the start of the reference pointer
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/push_front/
|
||||
void push_front(const string_t& token)
|
||||
{
|
||||
reference_tokens.insert(reference_tokens.begin(), token);
|
||||
}
|
||||
|
||||
/// @brief append an unescaped token at the start of the reference pointer
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/push_front/
|
||||
void push_front(string_t&& token)
|
||||
{
|
||||
reference_tokens.insert(reference_tokens.begin(), std::move(token));
|
||||
}
|
||||
|
||||
/// @brief remove last reference token
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/pop_back/
|
||||
void pop_back()
|
||||
|
||||
Reference in New Issue
Block a user