Add operator<<(json_pointer) (#3601)

* Add operator<< for json_pointer

* Deprecate json_pointer::operator string_t()

* Update documentation

* Move operator<<(basic_json) example

* Add example

* Add mkdocs-redirects

* Move operator<< and operator>> doc pages out of basic_json/

* Rename JSON pointer operator_string to operator_string_t

* Add unit test
This commit is contained in:
Florian Albrechtskirchinger
2022-07-28 22:12:23 +02:00
committed by GitHub
parent 7777300442
commit e3095f636f
20 changed files with 176 additions and 90 deletions

View File

@@ -12,6 +12,8 @@
#include <nlohmann/json.hpp>
using nlohmann::json;
#include <sstream>
TEST_CASE("JSON pointers")
{
SECTION("errors")
@@ -475,12 +477,16 @@ TEST_CASE("JSON pointers")
SECTION("string representation")
{
for (const auto* ptr :
for (const auto* ptr_str :
{"", "/foo", "/foo/0", "/", "/a~1b", "/c%d", "/e^f", "/g|h", "/i\\j", "/k\"l", "/ ", "/m~0n"
})
{
CHECK(json::json_pointer(ptr).to_string() == ptr);
CHECK(std::string(json::json_pointer(ptr)) == ptr);
json::json_pointer ptr(ptr_str);
std::stringstream ss;
ss << ptr;
CHECK(ptr.to_string() == ptr_str);
CHECK(std::string(ptr) == ptr_str);
CHECK(ss.str() == ptr_str);
}
}