1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-28 12:02:00 +03:00

JSON-pointer: add operator+() returning a new json_pointer

This commit is contained in:
Patrick Boettcher
2019-01-24 16:46:51 +01:00
parent e89c946451
commit a06e7f5d80
3 changed files with 96 additions and 4 deletions

View File

@ -11924,14 +11924,33 @@ class json_pointer
}
/*!
@brief remove and return last reference pointer
@throw out_of_range.405 if JSON pointer has no parent
@brief append a token at the end of the reference pointer
*/
void push_back(const std::string& tok)
{
reference_tokens.push_back(tok);
}
/*!
@brief append a key-token at the end of the reference pointer and return a new json-pointer.
*/
json_pointer operator+(const std::string& tok) const
{
auto ptr = *this;
ptr.push_back(tok);
return ptr;
}
/*!
@brief append a array-index-token at the end of the reference pointer and return a new json-pointer.
*/
json_pointer operator+(const size_t& index) const
{
auto ptr = *this;
ptr.push_back(std::to_string(index));
return ptr;
}
private:
/// return whether pointer points to the root document
bool is_root() const noexcept