Provide accessors into json_pointer
This commit is contained in:
parent
6c746460c6
commit
91971e394f
@ -19,6 +19,9 @@ class json_pointer
|
||||
friend class basic_json;
|
||||
|
||||
public:
|
||||
typedef std::vector<std::string>::const_iterator const_iterator;
|
||||
typedef std::vector<std::string>::const_reverse_iterator const_reverse_iterator;
|
||||
|
||||
/*!
|
||||
@brief create JSON pointer
|
||||
|
||||
@ -75,6 +78,38 @@ class json_pointer
|
||||
return to_string();
|
||||
}
|
||||
|
||||
const_iterator cbegin() const
|
||||
{
|
||||
return reference_tokens.cbegin();
|
||||
}
|
||||
|
||||
const_iterator cend() const
|
||||
{
|
||||
return reference_tokens.cend();
|
||||
}
|
||||
|
||||
const_reverse_iterator crbegin() const
|
||||
{
|
||||
return reference_tokens.crbegin();
|
||||
}
|
||||
|
||||
const_reverse_iterator crend() const
|
||||
{
|
||||
return reference_tokens.crend();
|
||||
}
|
||||
|
||||
json_pointer appended(std::string const& next) const
|
||||
{
|
||||
json_pointer copy(*this);
|
||||
copy.reference_tokens.push_back(next);
|
||||
return copy;
|
||||
}
|
||||
|
||||
json_pointer appended(size_t next) const
|
||||
{
|
||||
return appended(std::to_string(next));
|
||||
}
|
||||
|
||||
/*!
|
||||
@param[in] s reference token to be converted into an array index
|
||||
|
||||
|
||||
@ -10585,6 +10585,9 @@ class json_pointer
|
||||
friend class basic_json;
|
||||
|
||||
public:
|
||||
typedef std::vector<std::string>::const_iterator const_iterator;
|
||||
typedef std::vector<std::string>::const_reverse_iterator const_reverse_iterator;
|
||||
|
||||
/*!
|
||||
@brief create JSON pointer
|
||||
|
||||
@ -10641,6 +10644,38 @@ class json_pointer
|
||||
return to_string();
|
||||
}
|
||||
|
||||
const_iterator cbegin() const
|
||||
{
|
||||
return reference_tokens.cbegin();
|
||||
}
|
||||
|
||||
const_iterator cend() const
|
||||
{
|
||||
return reference_tokens.cend();
|
||||
}
|
||||
|
||||
const_reverse_iterator crbegin() const
|
||||
{
|
||||
return reference_tokens.crbegin();
|
||||
}
|
||||
|
||||
const_reverse_iterator crend() const
|
||||
{
|
||||
return reference_tokens.crend();
|
||||
}
|
||||
|
||||
json_pointer appended(std::string const& next) const
|
||||
{
|
||||
json_pointer copy(*this);
|
||||
copy.reference_tokens.push_back(next);
|
||||
return copy;
|
||||
}
|
||||
|
||||
json_pointer appended(size_t next) const
|
||||
{
|
||||
return appended(std::to_string(next));
|
||||
}
|
||||
|
||||
/*!
|
||||
@param[in] s reference token to be converted into an array index
|
||||
|
||||
|
||||
@ -441,6 +441,47 @@ TEST_CASE("JSON pointers")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("iterator access")
|
||||
{
|
||||
SECTION("forward iterator access")
|
||||
{
|
||||
auto ptr = "/foo/bar/c%d"_json_pointer;
|
||||
std::vector<std::string> components(ptr.cbegin(), ptr.cend());
|
||||
CHECK(components.size() == 3u);
|
||||
CHECK(components[0] == "foo");
|
||||
CHECK(components[1] == "bar");
|
||||
CHECK(components[2] == "c%d");
|
||||
}
|
||||
|
||||
SECTION("reverse iterator access")
|
||||
{
|
||||
auto ptr = "/foo/bar/c%d"_json_pointer;
|
||||
std::vector<std::string> rcomponents(ptr.crbegin(), ptr.crend());
|
||||
CHECK(rcomponents.size() == 3u);
|
||||
CHECK(rcomponents[2] == "foo");
|
||||
CHECK(rcomponents[1] == "bar");
|
||||
CHECK(rcomponents[0] == "c%d");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("appending")
|
||||
{
|
||||
SECTION("can append to empty string pointer")
|
||||
{
|
||||
auto ptr = ""_json_pointer;
|
||||
CHECK(ptr.to_string() == "");
|
||||
|
||||
ptr = ptr.appended("foo");
|
||||
CHECK(ptr.to_string() == "/foo");
|
||||
|
||||
ptr = ptr.appended("bar");
|
||||
CHECK(ptr.to_string() == "/foo/bar");
|
||||
|
||||
ptr = ptr.appended(10);
|
||||
CHECK(ptr.to_string() == "/foo/bar/10");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("conversion")
|
||||
{
|
||||
SECTION("array")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user