Add automatic rewind for at_pointer (#1624)

This commit is contained in:
Nicolas Boyer 2021-06-21 15:17:24 -04:00 committed by GitHub
parent 6cd04aa858
commit ce38fe7bea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 5 additions and 5 deletions

View File

@ -54,7 +54,7 @@ public:
* auto doc = parser.iterate(json);
* doc.at_pointer("/0/foo/a/1") == 20
*
* Note that at_pointer() does not automatically rewind between each call (call rewind() to reset).
* Note that at_pointer() automatically calls rewind between each call.
* Also note that at_pointer() relies on find_field() which implies that we do not unescape keys when matching.
* @return The value associated with the given JSON pointer, or:
* - NO_SUCH_FIELD if a field does not exist in an object

View File

@ -135,6 +135,7 @@ simdjson_really_inline simdjson_result<std::string_view> document::raw_json_toke
}
simdjson_really_inline simdjson_result<value> document::at_pointer(std::string_view json_pointer) noexcept {
rewind(); // Rewind the document each time at_pointer is called
if (json_pointer.empty()) {
return this->resume_value();
}

View File

@ -335,7 +335,7 @@ public:
* auto doc = parser.iterate(json);
* doc.at_pointer("//a/1") == 20
*
* Note that at_pointer() does not automatically rewind between each call (call rewind() to reset).
* Note that at_pointer() automatically calls rewind between each call.
* Also note that at_pointer() relies on find_field() which implies that we do not unescape keys when matching
*
* @return The value associated with the given JSON pointer, or:

View File

@ -91,7 +91,7 @@ public:
* auto doc = parser.iterate(json);
* doc.at_pointer("//a/1") == 20
*
* Note that at_pointer() does not automatically rewind between each call (call rewind() to reset).
* Note that at_pointer() automatically calls rewind between each call.
* Also note that at_pointer() relies on find_field() which implies that we do not unescape keys when matching.
*
* @return The value associated with the given JSON pointer, or:

View File

@ -330,7 +330,7 @@ public:
* auto doc = parser.iterate(json);
* doc.at_pointer("//a/1") == 20
*
* Note that at_pointer() does not automatically rewind between each call (call rewind() to reset).
* Note that at_pointer() automatically calls rewind between each call.
* Also note that at_pointer() relies on find_field() which implies that we do not unescape keys when matching
*
* @return The value associated with the given JSON pointer, or:

View File

@ -117,7 +117,6 @@ namespace json_pointer_tests {
std::string json_pointer = "/" + std::to_string(i) + "/tire_pressure/1";
ASSERT_SUCCESS(cars.at_pointer(json_pointer).get(x));
measured.push_back(x);
cars.rewind();
}
std::vector<double> expected = {39.9, 31, 30};