From 21342a41425a0c501bdc1471dc97cc5c298c8f44 Mon Sep 17 00:00:00 2001 From: Liqiang TAO Date: Tue, 11 Nov 2025 00:24:38 +0800 Subject: [PATCH] Fix some wrong content in doc (#2542) --- doc/basics.md | 8 ++++---- doc/dom.md | 2 +- doc/ondemand_design.md | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/basics.md b/doc/basics.md index c25262df8..54efb4b28 100644 --- a/doc/basics.md +++ b/doc/basics.md @@ -452,7 +452,7 @@ support for users who avoid exceptions. See [the simdjson error handling documen When you are iterating through an object, you are advancing through its keys and values. You should not also access the object or other objects. E.g. within a loop over `myobject`, you should not be accessing `myobject`. The following is an anti-pattern: `for(auto value: myobject) {myobject["mykey"]}`. You should never reset an object as you are iterating through it. The following is an anti-pattern: `for(auto value: myobject) {myobject.reset()}`. -* **Array Index:** Because it is forward-only, you cannot look up an array element by index by index. Instead, +* **Array Index:** Because it is forward-only, you cannot look up an array element by index. Instead, you should iterate through the array and keep an index yourself. Exceptionally, if need a single value out of the array, you may use an array access (e.g., `array[1]`). You should never reset an array as you are iterating through it. The following is an anti-pattern: `for(auto value: myarray) {myarray.reset()}`. * **Field Access:** To get the value of the "foo" field in an object, use `object["foo"]`. This will @@ -527,13 +527,13 @@ support for users who avoid exceptions. See [the simdjson error handling documen > auto silly_json = R"( { "test": "result" } )"_padded; > ondemand::document doc = parser.iterate(silly_json); > std::cout << simdjson::to_json_string(doc["test"]) << std::endl; // Requires simdjson 1.0 or better - >```` + > ``` > ```cpp > // retrieves an unescaped string value as a string_view instance > auto silly_json = R"( { "test": "result" } )"_padded; > ondemand::document doc = parser.iterate(silly_json); > std::cout << std::string_view(doc["test"]) << std::endl; - >```` + > ``` You can use `to_json_string` to efficiently extract components of a JSON document to reconstruct a new JSON document, as in the following example: > ```cpp > auto cars_json = R"( [ @@ -562,7 +562,7 @@ support for users who avoid exceptions. See [the simdjson error handling documen > oss << "]"; > auto json_string = oss.str(); > // json_string == "[[ 40.1, 39.9, 37.7, 40.4 ],[ 30.1, 31.0, 28.6, 28.7 ]]" - >```` + > ``` * **Extracting Values (without exceptions):** You can use a variant usage of `get()` with error codes to avoid exceptions. You first declare the variable of the appropriate type (`double`, `uint64_t`, `int64_t`, `bool`, `ondemand::object` and `ondemand::array`) and pass it by reference diff --git a/doc/dom.md b/doc/dom.md index a13dd2c35..c936e6a37 100644 --- a/doc/dom.md +++ b/doc/dom.md @@ -843,7 +843,7 @@ memcpy(padded_json_copy.get(), json, json_len); memset(padded_json_copy.get() + json_len, 0, SIMDJSON_PADDING); simdjson::dom::parser parser; simdjson::dom::element element = parser.parse(padded_json_copy.get(), json_len, false); -```` +``` Setting the `realloc_if_needed` parameter `false` in this manner may lead to better performance since copies are avoided, but it requires that the user takes more responsibilities: the simdjson library cannot verify that the input buffer was padded with SIMDJSON_PADDING extra bytes. diff --git a/doc/ondemand_design.md b/doc/ondemand_design.md index 9e7cb941e..507431111 100644 --- a/doc/ondemand_design.md +++ b/doc/ondemand_design.md @@ -545,7 +545,7 @@ To help visualize the algorithm, we'll walk through the example C++ given at the "statuses": [ { "id": 1, "text": "first!", "user": { "screen_name": "lemire", "name": "Daniel" }, "retweet_count": 40 }, { "id": 2, "text": "second!", "user": { "screen_name": "jkeiser2", "name": "John" }, "retweet_count": 3 } - ^ (depth 3 - root > statuses > tweet) + ^ (depth 4 - root > statuses > tweet > field) ], "search_metadata": { "count": 2 } }