iterating over a simdjson_result<padded_string> (#2614)

This commit is contained in:
Daniel Lemire
2026-02-27 11:01:39 -05:00
committed by GitHub
parent 7ec4572d33
commit 7dcc196f66
2 changed files with 22 additions and 1 deletions
+1 -1
View File
@@ -764,7 +764,7 @@ bool basics_1() {
TEST_START();
ondemand::parser parser;
auto json = padded_string::load("twitter.json");
auto json = padded_string::load("twitter.json"); // this is a simdjson_result<padded_string>
ondemand::document doc = parser.iterate(json); // load and parse a file
simdjson_unused auto unused_doc = doc.get_object();
+21
View File
@@ -20,6 +20,26 @@ namespace twitter_tests {
TEST_SUCCEED();
}
#if SIMDJSON_EXCEPTIONS
bool twitter_result_example() {
TEST_START();
simdjson_result<padded_string> json = padded_string::load(TWITTER_JSON);
ondemand::parser parser;
auto doc = parser.iterate(json);
for (ondemand::object tweet : doc["statuses"]) {
uint64_t id = tweet["id"];
std::string_view text = tweet["text"];
std::string_view screen_name = tweet["user"]["screen_name"];
uint64_t retweets = tweet["retweet_count"];
uint64_t favorites = tweet["favorite_count"];
(void) id;
(void) text;
(void) retweets;
(void) favorites;
(void) screen_name;
}
TEST_SUCCEED();
}
bool twitter_example() {
TEST_START();
padded_string json;
@@ -182,6 +202,7 @@ namespace twitter_tests {
twitter_default_profile() &&
twitter_image_sizes() &&
#if SIMDJSON_EXCEPTIONS
twitter_result_example() &&
twitter_count_exception() &&
twitter_example() &&
twitter_default_profile_exception() &&