mirror of
https://github.com/nlohmann/json.git
synced 2025-07-13 20:21:48 +03:00
implemented remove
This commit is contained in:
@ -8279,6 +8279,18 @@ class basic_json
|
||||
: reference_tokens(split(s))
|
||||
{}
|
||||
|
||||
std::string pop_back()
|
||||
{
|
||||
if (reference_tokens.empty())
|
||||
{
|
||||
throw std::domain_error("JSON pointer has no parent");
|
||||
}
|
||||
|
||||
auto last = reference_tokens.back();
|
||||
reference_tokens.pop_back();
|
||||
return last;
|
||||
}
|
||||
|
||||
private:
|
||||
/*!
|
||||
@brief create and return a reference to the pointed to value
|
||||
@ -8730,7 +8742,7 @@ class basic_json
|
||||
|
||||
private:
|
||||
/// the reference tokens
|
||||
const std::vector<std::string> reference_tokens {};
|
||||
std::vector<std::string> reference_tokens {};
|
||||
};
|
||||
|
||||
////////////////////////////
|
||||
@ -8849,7 +8861,7 @@ class basic_json
|
||||
|
||||
const std::string op = it_op->second;
|
||||
const std::string path = it_path->second;
|
||||
const json_pointer ptr(path);
|
||||
json_pointer ptr(path);
|
||||
|
||||
if (op == "add")
|
||||
{
|
||||
@ -8862,6 +8874,16 @@ class basic_json
|
||||
}
|
||||
else if (op == "remove")
|
||||
{
|
||||
const auto last_path = ptr.pop_back();
|
||||
basic_json& parent = result.at(ptr);
|
||||
if (parent.is_object())
|
||||
{
|
||||
parent.erase(parent.find(last_path));
|
||||
}
|
||||
else if (parent.is_array())
|
||||
{
|
||||
parent.erase(parent.begin() + std::stoi(last_path));
|
||||
}
|
||||
}
|
||||
else if (op == "replace")
|
||||
{
|
||||
|
Reference in New Issue
Block a user