mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9dd6e9c959 | |||
| 6db330c1a2 | |||
| 993ac4b87c | |||
| 35e87896f0 | |||
| f7e281cadc | |||
| 13405afd4b | |||
| 24b44309fb | |||
| e11ad58aad |
+3
-3
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14)
|
|||||||
project(
|
project(
|
||||||
simdjson
|
simdjson
|
||||||
# The version number is modified by tools/release.py
|
# The version number is modified by tools/release.py
|
||||||
VERSION 3.3.0
|
VERSION 3.4.0
|
||||||
DESCRIPTION "Parsing gigabytes of JSON per second"
|
DESCRIPTION "Parsing gigabytes of JSON per second"
|
||||||
HOMEPAGE_URL "https://simdjson.org/"
|
HOMEPAGE_URL "https://simdjson.org/"
|
||||||
LANGUAGES CXX C
|
LANGUAGES CXX C
|
||||||
@@ -20,8 +20,8 @@ string(
|
|||||||
# ---- Options, variables ----
|
# ---- Options, variables ----
|
||||||
|
|
||||||
# These version numbers are modified by tools/release.py
|
# These version numbers are modified by tools/release.py
|
||||||
set(SIMDJSON_LIB_VERSION "16.0.0" CACHE STRING "simdjson library version")
|
set(SIMDJSON_LIB_VERSION "17.0.0" CACHE STRING "simdjson library version")
|
||||||
set(SIMDJSON_LIB_SOVERSION "16" CACHE STRING "simdjson library soversion")
|
set(SIMDJSON_LIB_SOVERSION "17" CACHE STRING "simdjson library soversion")
|
||||||
|
|
||||||
option(SIMDJSON_BUILD_STATIC_LIB "Build simdjson_static library along with simdjson" OFF)
|
option(SIMDJSON_BUILD_STATIC_LIB "Build simdjson_static library along with simdjson" OFF)
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ PROJECT_NAME = simdjson
|
|||||||
# could be handy for archiving the generated documentation or if some version
|
# could be handy for archiving the generated documentation or if some version
|
||||||
# control system is used.
|
# control system is used.
|
||||||
|
|
||||||
PROJECT_NUMBER = "3.3.0"
|
PROJECT_NUMBER = "3.4.0"
|
||||||
|
|
||||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||||
# for a project that appears at the top of each page and should give viewer a
|
# for a project that appears at the top of each page and should give viewer a
|
||||||
|
|||||||
+38
-3
@@ -179,8 +179,8 @@ strcpy(json, "[1]");
|
|||||||
ondemand::document doc = parser.iterate(json, strlen(json), sizeof(json));
|
ondemand::document doc = parser.iterate(json, strlen(json), sizeof(json));
|
||||||
```
|
```
|
||||||
|
|
||||||
The simdjson library will also accept `std::string` instances, as long as the `capacity()` of
|
The simdjson library will also accept `std::string` instances. If the provided
|
||||||
the string exceeds the `size()` by at least `SIMDJSON_PADDING`. You can increase the `capacity()` with the `reserve()` function of your strings.
|
reference is non-const, it will allocate padding as needed.
|
||||||
|
|
||||||
You can copy your data directly on a `simdjson::padded_string` as follows:
|
You can copy your data directly on a `simdjson::padded_string` as follows:
|
||||||
|
|
||||||
@@ -1653,7 +1653,7 @@ JSON string to a user-provided buffer:
|
|||||||
|
|
||||||
General Direct Access to the Raw JSON String
|
General Direct Access to the Raw JSON String
|
||||||
--------------------------------
|
--------------------------------
|
||||||
If your value is a string, the `raw_json_string` gives you direct access to the unprocess
|
If your value is a string, the `raw_json_string` you with `get_raw_json_string()` gives you direct access to the unprocessed
|
||||||
string. The simdjson library allows you to have access to the raw underlying JSON
|
string. The simdjson library allows you to have access to the raw underlying JSON
|
||||||
more generally.
|
more generally.
|
||||||
|
|
||||||
@@ -1722,6 +1722,41 @@ obj.reset(); // revise the object
|
|||||||
uint64_t x = obj["value"]; // gives me 123
|
uint64_t x = obj["value"]; // gives me 123
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Storing Directly into an Existing std::string Instance
|
||||||
|
-----------------------------------------------------
|
||||||
|
|
||||||
|
The simdjson library favours the use of `std::string_view` instances because
|
||||||
|
it tends to lead to better performance due to causing fewer memory allocations.
|
||||||
|
However, they are cases where you need to store a string result in an `std::string``
|
||||||
|
instance. You can do so with a version of the `to_string()` method which takes as
|
||||||
|
a parameter a reference to an `std::string`.
|
||||||
|
|
||||||
|
```C++
|
||||||
|
auto json = R"({
|
||||||
|
"name": "Daniel",
|
||||||
|
"age": 42
|
||||||
|
})"_padded;
|
||||||
|
ondemand::parser parser;
|
||||||
|
ondemand::document doc = parser.iterate(json);
|
||||||
|
std::string name;
|
||||||
|
doc["name"].get_string(name);
|
||||||
|
```
|
||||||
|
|
||||||
|
The same routine can be written without exceptions handling:
|
||||||
|
|
||||||
|
```C++
|
||||||
|
std::string name;
|
||||||
|
auto err = doc["name"].get_string(name);
|
||||||
|
if(err) { /* handle error */ }
|
||||||
|
```
|
||||||
|
|
||||||
|
The `std::string` instance, once created, is independent. Unlike our `std::string_view` instances, it does not point at data that is
|
||||||
|
within our `parser` instance. The same caveat applies: you should
|
||||||
|
only consume a JSON string once.
|
||||||
|
|
||||||
|
You should be mindful of the trade-off: allocating multiple
|
||||||
|
`std::string` instances can become expensive.
|
||||||
|
|
||||||
Thread Safety
|
Thread Safety
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
|||||||
@@ -410,6 +410,12 @@ inline simdjson_result<element> element::at_key(std::string_view key) const noex
|
|||||||
inline simdjson_result<element> element::at_key_case_insensitive(std::string_view key) const noexcept {
|
inline simdjson_result<element> element::at_key_case_insensitive(std::string_view key) const noexcept {
|
||||||
return get<object>().at_key_case_insensitive(key);
|
return get<object>().at_key_case_insensitive(key);
|
||||||
}
|
}
|
||||||
|
inline bool element::operator<(const element &other) const noexcept {
|
||||||
|
return tape.json_index < other.tape.json_index;
|
||||||
|
}
|
||||||
|
inline bool element::operator==(const element &other) const noexcept {
|
||||||
|
return tape.json_index == other.tape.json_index;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool element::dump_raw_tape(std::ostream &out) const noexcept {
|
inline bool element::dump_raw_tape(std::ostream &out) const noexcept {
|
||||||
SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
|
SIMDJSON_DEVELOPMENT_ASSERT(tape.usable()); // https://github.com/simdjson/simdjson/issues/1914
|
||||||
|
|||||||
@@ -211,7 +211,11 @@ public:
|
|||||||
inline simdjson_result<T> get() const noexcept {
|
inline simdjson_result<T> get() const noexcept {
|
||||||
// Unless the simdjson library provides an inline implementation, calling this method should
|
// Unless the simdjson library provides an inline implementation, calling this method should
|
||||||
// immediately fail.
|
// immediately fail.
|
||||||
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library.");
|
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
|
||||||
|
"The supported types are Boolean (bool), numbers (double, uint64_t, int64_t), "
|
||||||
|
"strings (std::string_view, const char *), arrays (dom::array) and objects (dom::object). "
|
||||||
|
"We recommand you use get_double(), get_bool(), get_uint64(), get_int64(), "
|
||||||
|
"get_object(), get_array() or get_string() instead of the get template.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -451,6 +455,22 @@ public:
|
|||||||
*/
|
*/
|
||||||
inline simdjson_result<element> at_key_case_insensitive(std::string_view key) const noexcept;
|
inline simdjson_result<element> at_key_case_insensitive(std::string_view key) const noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* operator< defines a total order for element allowing to use them in
|
||||||
|
* ordered C++ STL containers
|
||||||
|
*
|
||||||
|
* @return TRUE if the key appears before the other one in the tape
|
||||||
|
*/
|
||||||
|
inline bool operator<(const element &other) const noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* operator== allows to verify if two element values reference the
|
||||||
|
* same JSON item
|
||||||
|
*
|
||||||
|
* @return TRUE if the two values references the same JSON element
|
||||||
|
*/
|
||||||
|
inline bool operator==(const element &other) const noexcept;
|
||||||
|
|
||||||
/** @private for debugging. Prints out the root element. */
|
/** @private for debugging. Prints out the root element. */
|
||||||
inline bool dump_raw_tape(std::ostream &out) const noexcept;
|
inline bool dump_raw_tape(std::ostream &out) const noexcept;
|
||||||
|
|
||||||
|
|||||||
@@ -128,6 +128,9 @@ simdjson_inline simdjson_result<double> document::get_double_in_string() noexcep
|
|||||||
simdjson_inline simdjson_result<std::string_view> document::get_string(bool allow_replacement) noexcept {
|
simdjson_inline simdjson_result<std::string_view> document::get_string(bool allow_replacement) noexcept {
|
||||||
return get_root_value_iterator().get_root_string(true, allow_replacement);
|
return get_root_value_iterator().get_root_string(true, allow_replacement);
|
||||||
}
|
}
|
||||||
|
simdjson_inline error_code document::get_string(std::string& receiver, bool allow_replacement) noexcept {
|
||||||
|
return get_root_value_iterator().get_root_string(receiver, true, allow_replacement);
|
||||||
|
}
|
||||||
simdjson_inline simdjson_result<std::string_view> document::get_wobbly_string() noexcept {
|
simdjson_inline simdjson_result<std::string_view> document::get_wobbly_string() noexcept {
|
||||||
return get_root_value_iterator().get_root_wobbly_string(true);
|
return get_root_value_iterator().get_root_wobbly_string(true);
|
||||||
}
|
}
|
||||||
@@ -397,6 +400,10 @@ simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLE
|
|||||||
if (error()) { return error(); }
|
if (error()) { return error(); }
|
||||||
return first.get_string(allow_replacement);
|
return first.get_string(allow_replacement);
|
||||||
}
|
}
|
||||||
|
simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_string(std::string& receiver, bool allow_replacement) noexcept {
|
||||||
|
if (error()) { return error(); }
|
||||||
|
return first.get_string(receiver, allow_replacement);
|
||||||
|
}
|
||||||
simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_wobbly_string() noexcept {
|
simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document>::get_wobbly_string() noexcept {
|
||||||
if (error()) { return error(); }
|
if (error()) { return error(); }
|
||||||
return first.get_wobbly_string();
|
return first.get_wobbly_string();
|
||||||
@@ -583,6 +590,7 @@ simdjson_inline simdjson_result<int64_t> document_reference::get_int64_in_string
|
|||||||
simdjson_inline simdjson_result<double> document_reference::get_double() noexcept { return doc->get_root_value_iterator().get_root_double(false); }
|
simdjson_inline simdjson_result<double> document_reference::get_double() noexcept { return doc->get_root_value_iterator().get_root_double(false); }
|
||||||
simdjson_inline simdjson_result<double> document_reference::get_double_in_string() noexcept { return doc->get_root_value_iterator().get_root_double(false); }
|
simdjson_inline simdjson_result<double> document_reference::get_double_in_string() noexcept { return doc->get_root_value_iterator().get_root_double(false); }
|
||||||
simdjson_inline simdjson_result<std::string_view> document_reference::get_string(bool allow_replacement) noexcept { return doc->get_root_value_iterator().get_root_string(false, allow_replacement); }
|
simdjson_inline simdjson_result<std::string_view> document_reference::get_string(bool allow_replacement) noexcept { return doc->get_root_value_iterator().get_root_string(false, allow_replacement); }
|
||||||
|
simdjson_inline error_code document_reference::get_string(std::string& receiver, bool allow_replacement) noexcept { return doc->get_root_value_iterator().get_root_string(receiver, false, allow_replacement); }
|
||||||
simdjson_inline simdjson_result<std::string_view> document_reference::get_wobbly_string() noexcept { return doc->get_root_value_iterator().get_root_wobbly_string(false); }
|
simdjson_inline simdjson_result<std::string_view> document_reference::get_wobbly_string() noexcept { return doc->get_root_value_iterator().get_root_wobbly_string(false); }
|
||||||
simdjson_inline simdjson_result<raw_json_string> document_reference::get_raw_json_string() noexcept { return doc->get_root_value_iterator().get_root_raw_json_string(false); }
|
simdjson_inline simdjson_result<raw_json_string> document_reference::get_raw_json_string() noexcept { return doc->get_root_value_iterator().get_root_raw_json_string(false); }
|
||||||
simdjson_inline simdjson_result<bool> document_reference::get_bool() noexcept { return doc->get_root_value_iterator().get_root_bool(false); }
|
simdjson_inline simdjson_result<bool> document_reference::get_bool() noexcept { return doc->get_root_value_iterator().get_root_bool(false); }
|
||||||
@@ -719,6 +727,10 @@ simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLE
|
|||||||
if (error()) { return error(); }
|
if (error()) { return error(); }
|
||||||
return first.get_string(allow_replacement);
|
return first.get_string(allow_replacement);
|
||||||
}
|
}
|
||||||
|
simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_string(std::string& receiver, bool allow_replacement) noexcept {
|
||||||
|
if (error()) { return error(); }
|
||||||
|
return first.get_string(receiver, allow_replacement);
|
||||||
|
}
|
||||||
simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_wobbly_string() noexcept {
|
simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::document_reference>::get_wobbly_string() noexcept {
|
||||||
if (error()) { return error(); }
|
if (error()) { return error(); }
|
||||||
return first.get_wobbly_string();
|
return first.get_wobbly_string();
|
||||||
|
|||||||
@@ -100,6 +100,20 @@ public:
|
|||||||
* @returns INCORRECT_TYPE if the JSON value is not a string.
|
* @returns INCORRECT_TYPE if the JSON value is not a string.
|
||||||
*/
|
*/
|
||||||
simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
|
simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
|
||||||
|
/**
|
||||||
|
* Attempts to fill the provided std::string reference with the parsed value of the current string.
|
||||||
|
*
|
||||||
|
* The string is guaranteed to be valid UTF-8.
|
||||||
|
*
|
||||||
|
* Important: a value should be consumed once. Calling get_string() twice on the same value
|
||||||
|
* is an error.
|
||||||
|
*
|
||||||
|
* Performance: This method may be slower than get_string() or get_string(bool) because it may need to allocate memory.
|
||||||
|
* We recommend you avoid allocating an std::string unless you need to.
|
||||||
|
*
|
||||||
|
* @returns INCORRECT_TYPE if the JSON value is not a string. Otherwise, we return SUCCESS.
|
||||||
|
*/
|
||||||
|
simdjson_inline error_code get_string(std::string& receiver, bool allow_replacement = false) noexcept;
|
||||||
/**
|
/**
|
||||||
* Cast this JSON value to a string.
|
* Cast this JSON value to a string.
|
||||||
*
|
*
|
||||||
@@ -160,13 +174,19 @@ public:
|
|||||||
template<typename T> simdjson_inline simdjson_result<T> get() & noexcept {
|
template<typename T> simdjson_inline simdjson_result<T> get() & noexcept {
|
||||||
// Unless the simdjson library provides an inline implementation, calling this method should
|
// Unless the simdjson library provides an inline implementation, calling this method should
|
||||||
// immediately fail.
|
// immediately fail.
|
||||||
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library.");
|
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
|
||||||
|
"The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
|
||||||
|
"int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
|
||||||
|
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template.");
|
||||||
}
|
}
|
||||||
/** @overload template<typename T> simdjson_result<T> get() & noexcept */
|
/** @overload template<typename T> simdjson_result<T> get() & noexcept */
|
||||||
template<typename T> simdjson_inline simdjson_result<T> get() && noexcept {
|
template<typename T> simdjson_inline simdjson_result<T> get() && noexcept {
|
||||||
// Unless the simdjson library provides an inline implementation, calling this method should
|
// Unless the simdjson library provides an inline implementation, calling this method should
|
||||||
// immediately fail.
|
// immediately fail.
|
||||||
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library.");
|
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
|
||||||
|
"The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
|
||||||
|
"int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
|
||||||
|
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -618,6 +638,7 @@ public:
|
|||||||
simdjson_inline simdjson_result<double> get_double() noexcept;
|
simdjson_inline simdjson_result<double> get_double() noexcept;
|
||||||
simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
|
simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
|
||||||
simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
|
simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
|
||||||
|
simdjson_inline error_code get_string(std::string& receiver, bool allow_replacement = false) noexcept;
|
||||||
simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
|
simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
|
||||||
simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
|
simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
|
||||||
simdjson_inline simdjson_result<bool> get_bool() noexcept;
|
simdjson_inline simdjson_result<bool> get_bool() noexcept;
|
||||||
@@ -687,6 +708,7 @@ public:
|
|||||||
simdjson_inline simdjson_result<double> get_double() noexcept;
|
simdjson_inline simdjson_result<double> get_double() noexcept;
|
||||||
simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
|
simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
|
||||||
simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
|
simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
|
||||||
|
simdjson_inline error_code get_string(std::string& receiver, bool allow_replacement = false) noexcept;
|
||||||
simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
|
simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
|
||||||
simdjson_inline simdjson_result<bool> get_bool() noexcept;
|
simdjson_inline simdjson_result<bool> get_bool() noexcept;
|
||||||
@@ -759,6 +781,7 @@ public:
|
|||||||
simdjson_inline simdjson_result<double> get_double() noexcept;
|
simdjson_inline simdjson_result<double> get_double() noexcept;
|
||||||
simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
|
simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
|
||||||
simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
|
simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
|
||||||
|
simdjson_inline error_code get_string(std::string& receiver, bool allow_replacement = false) noexcept;
|
||||||
simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
|
simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
|
||||||
simdjson_inline simdjson_result<bool> get_bool() noexcept;
|
simdjson_inline simdjson_result<bool> get_bool() noexcept;
|
||||||
|
|||||||
@@ -254,6 +254,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
simdjson_inline simdjson_result<std::string_view> unescape(raw_json_string in, bool allow_replacement) noexcept;
|
simdjson_inline simdjson_result<std::string_view> unescape(raw_json_string in, bool allow_replacement) noexcept;
|
||||||
simdjson_inline simdjson_result<std::string_view> unescape_wobbly(raw_json_string in) noexcept;
|
simdjson_inline simdjson_result<std::string_view> unescape_wobbly(raw_json_string in) noexcept;
|
||||||
|
|
||||||
simdjson_inline void reenter_child(token_position position, depth_t child_depth) noexcept;
|
simdjson_inline void reenter_child(token_position position, depth_t child_depth) noexcept;
|
||||||
|
|
||||||
simdjson_inline error_code consume_character(char c) noexcept;
|
simdjson_inline error_code consume_character(char c) noexcept;
|
||||||
|
|||||||
@@ -68,6 +68,13 @@ simdjson_warn_unused simdjson_inline simdjson_result<document> parser::iterate(s
|
|||||||
return iterate(padded_string_view(json, allocated));
|
return iterate(padded_string_view(json, allocated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
simdjson_warn_unused simdjson_inline simdjson_result<document> parser::iterate(std::string &json) & noexcept {
|
||||||
|
if(json.capacity() - json.size() < SIMDJSON_PADDING) {
|
||||||
|
json.reserve(json.size() + SIMDJSON_PADDING);
|
||||||
|
}
|
||||||
|
return iterate(padded_string_view(json));
|
||||||
|
}
|
||||||
|
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<document> parser::iterate(const std::string &json) & noexcept {
|
simdjson_warn_unused simdjson_inline simdjson_result<document> parser::iterate(const std::string &json) & noexcept {
|
||||||
return iterate(padded_string_view(json));
|
return iterate(padded_string_view(json));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ public:
|
|||||||
/** @overload simdjson_result<document> iterate(padded_string_view json) & noexcept */
|
/** @overload simdjson_result<document> iterate(padded_string_view json) & noexcept */
|
||||||
simdjson_warn_unused simdjson_result<document> iterate(const std::string &json) & noexcept;
|
simdjson_warn_unused simdjson_result<document> iterate(const std::string &json) & noexcept;
|
||||||
/** @overload simdjson_result<document> iterate(padded_string_view json) & noexcept */
|
/** @overload simdjson_result<document> iterate(padded_string_view json) & noexcept */
|
||||||
|
simdjson_warn_unused simdjson_result<document> iterate(std::string &json) & noexcept;
|
||||||
|
/** @overload simdjson_result<document> iterate(padded_string_view json) & noexcept */
|
||||||
simdjson_warn_unused simdjson_result<document> iterate(const simdjson_result<padded_string> &json) & noexcept;
|
simdjson_warn_unused simdjson_result<document> iterate(const simdjson_result<padded_string> &json) & noexcept;
|
||||||
/** @overload simdjson_result<document> iterate(padded_string_view json) & noexcept */
|
/** @overload simdjson_result<document> iterate(padded_string_view json) & noexcept */
|
||||||
simdjson_warn_unused simdjson_result<document> iterate(const simdjson_result<padded_string_view> &json) & noexcept;
|
simdjson_warn_unused simdjson_result<document> iterate(const simdjson_result<padded_string_view> &json) & noexcept;
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ simdjson_inline simdjson_result<raw_json_string> value::get_raw_json_string() no
|
|||||||
simdjson_inline simdjson_result<std::string_view> value::get_string(bool allow_replacement) noexcept {
|
simdjson_inline simdjson_result<std::string_view> value::get_string(bool allow_replacement) noexcept {
|
||||||
return iter.get_string(allow_replacement);
|
return iter.get_string(allow_replacement);
|
||||||
}
|
}
|
||||||
|
simdjson_inline error_code value::get_string(std::string& receiver, bool allow_replacement) noexcept {
|
||||||
|
return iter.get_string(receiver, allow_replacement);
|
||||||
|
}
|
||||||
simdjson_inline simdjson_result<std::string_view> value::get_wobbly_string() noexcept {
|
simdjson_inline simdjson_result<std::string_view> value::get_wobbly_string() noexcept {
|
||||||
return iter.get_wobbly_string();
|
return iter.get_wobbly_string();
|
||||||
}
|
}
|
||||||
@@ -319,6 +322,10 @@ simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLE
|
|||||||
if (error()) { return error(); }
|
if (error()) { return error(); }
|
||||||
return first.get_string(allow_replacement);
|
return first.get_string(allow_replacement);
|
||||||
}
|
}
|
||||||
|
simdjson_inline error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_string(std::string& receiver, bool allow_replacement) noexcept {
|
||||||
|
if (error()) { return error(); }
|
||||||
|
return first.get_string(receiver, allow_replacement);
|
||||||
|
}
|
||||||
simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_wobbly_string() noexcept {
|
simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::value>::get_wobbly_string() noexcept {
|
||||||
if (error()) { return error(); }
|
if (error()) { return error(); }
|
||||||
return first.get_wobbly_string();
|
return first.get_wobbly_string();
|
||||||
|
|||||||
@@ -38,7 +38,10 @@ public:
|
|||||||
template<typename T> simdjson_inline simdjson_result<T> get() noexcept {
|
template<typename T> simdjson_inline simdjson_result<T> get() noexcept {
|
||||||
// Unless the simdjson library provides an inline implementation, calling this method should
|
// Unless the simdjson library provides an inline implementation, calling this method should
|
||||||
// immediately fail.
|
// immediately fail.
|
||||||
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library.");
|
static_assert(!sizeof(T), "The get method with given type is not implemented by the simdjson library. "
|
||||||
|
"The supported types are ondemand::object, ondemand::array, raw_json_string, std::string_view, uint64_t, "
|
||||||
|
"int64_t, double, and bool. We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
|
||||||
|
" get_object(), get_array(), get_raw_json_string(), or get_string() instead of the get template.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -132,6 +135,20 @@ public:
|
|||||||
*/
|
*/
|
||||||
simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
|
simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to fill the provided std::string reference with the parsed value of the current string.
|
||||||
|
*
|
||||||
|
* The string is guaranteed to be valid UTF-8.
|
||||||
|
*
|
||||||
|
* Important: a value should be consumed once. Calling get_string() twice on the same value
|
||||||
|
* is an error.
|
||||||
|
*
|
||||||
|
* Performance: This method may be slower than get_string() or get_string(bool) because it may need to allocate memory.
|
||||||
|
* We recommend you avoid allocating an std::string unless you need to.
|
||||||
|
*
|
||||||
|
* @returns INCORRECT_TYPE if the JSON value is not a string. Otherwise, we return SUCCESS.
|
||||||
|
*/
|
||||||
|
simdjson_inline error_code get_string(std::string& receiver, bool allow_replacement = false) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cast this JSON value to a "wobbly" string.
|
* Cast this JSON value to a "wobbly" string.
|
||||||
@@ -602,6 +619,7 @@ public:
|
|||||||
simdjson_inline simdjson_result<double> get_double() noexcept;
|
simdjson_inline simdjson_result<double> get_double() noexcept;
|
||||||
simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
|
simdjson_inline simdjson_result<double> get_double_in_string() noexcept;
|
||||||
simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
|
simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement = false) noexcept;
|
||||||
|
simdjson_inline error_code get_string(std::string& receiver, bool allow_replacement = false) noexcept;
|
||||||
simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
|
simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
|
||||||
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
|
simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> get_raw_json_string() noexcept;
|
||||||
simdjson_inline simdjson_result<bool> get_bool() noexcept;
|
simdjson_inline simdjson_result<bool> get_bool() noexcept;
|
||||||
|
|||||||
@@ -513,6 +513,13 @@ simdjson_warn_unused simdjson_inline simdjson_result<bool> value_iterator::parse
|
|||||||
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> value_iterator::get_string(bool allow_replacement) noexcept {
|
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> value_iterator::get_string(bool allow_replacement) noexcept {
|
||||||
return get_raw_json_string().unescape(json_iter(), allow_replacement);
|
return get_raw_json_string().unescape(json_iter(), allow_replacement);
|
||||||
}
|
}
|
||||||
|
simdjson_warn_unused simdjson_inline error_code value_iterator::get_string(std::string& receiver, bool allow_replacement) noexcept {
|
||||||
|
std::string_view content;
|
||||||
|
auto err = get_string(allow_replacement).get(content);
|
||||||
|
if (err) { return err; }
|
||||||
|
receiver = std::string(content);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> value_iterator::get_wobbly_string() noexcept {
|
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> value_iterator::get_wobbly_string() noexcept {
|
||||||
return get_raw_json_string().unescape_wobbly(json_iter());
|
return get_raw_json_string().unescape_wobbly(json_iter());
|
||||||
}
|
}
|
||||||
@@ -636,6 +643,13 @@ simdjson_inline simdjson_result<number> value_iterator::get_root_number(bool che
|
|||||||
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> value_iterator::get_root_string(bool check_trailing, bool allow_replacement) noexcept {
|
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> value_iterator::get_root_string(bool check_trailing, bool allow_replacement) noexcept {
|
||||||
return get_root_raw_json_string(check_trailing).unescape(json_iter(), allow_replacement);
|
return get_root_raw_json_string(check_trailing).unescape(json_iter(), allow_replacement);
|
||||||
}
|
}
|
||||||
|
simdjson_warn_unused simdjson_inline error_code value_iterator::get_root_string(std::string& receiver, bool check_trailing, bool allow_replacement) noexcept {
|
||||||
|
std::string_view content;
|
||||||
|
auto err = get_root_string(check_trailing, allow_replacement).get(content);
|
||||||
|
if (err) { return err; }
|
||||||
|
receiver = std::string(content);
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> value_iterator::get_root_wobbly_string(bool check_trailing) noexcept {
|
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> value_iterator::get_root_wobbly_string(bool check_trailing) noexcept {
|
||||||
return get_root_raw_json_string(check_trailing).unescape_wobbly(json_iter());
|
return get_root_raw_json_string(check_trailing).unescape_wobbly(json_iter());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -296,6 +296,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement) noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> get_string(bool allow_replacement) noexcept;
|
||||||
|
simdjson_warn_unused simdjson_inline error_code get_string(std::string& receiver, bool allow_replacement) noexcept;
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> get_wobbly_string() noexcept;
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<raw_json_string> get_raw_json_string() noexcept;
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<uint64_t> get_uint64() noexcept;
|
||||||
@@ -312,7 +313,8 @@ public:
|
|||||||
simdjson_warn_unused simdjson_inline simdjson_result<number> get_number() noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<number> get_number() noexcept;
|
||||||
|
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> get_root_string(bool check_trailing, bool allow_replacement) noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> get_root_string(bool check_trailing, bool allow_replacement) noexcept;
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> get_root_wobbly_string(bool check_trailing) noexcept;
|
simdjson_warn_unused simdjson_inline error_code get_root_string(std::string& receiver, bool check_trailing, bool allow_replacement) noexcept;
|
||||||
|
simdjson_warn_unused simdjson_inline simdjson_result<std::string_view> get_root_wobbly_string(bool check_trailing) noexcept;
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<raw_json_string> get_root_raw_json_string(bool check_trailing) noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<raw_json_string> get_root_raw_json_string(bool check_trailing) noexcept;
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<uint64_t> get_root_uint64(bool check_trailing) noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<uint64_t> get_root_uint64(bool check_trailing) noexcept;
|
||||||
simdjson_warn_unused simdjson_inline simdjson_result<uint64_t> get_root_uint64_in_string(bool check_trailing) noexcept;
|
simdjson_warn_unused simdjson_inline simdjson_result<uint64_t> get_root_uint64_in_string(bool check_trailing) noexcept;
|
||||||
|
|||||||
@@ -58,11 +58,8 @@
|
|||||||
|
|
||||||
#if SIMDJSON_IS_32BITS
|
#if SIMDJSON_IS_32BITS
|
||||||
#ifndef SIMDJSON_NO_PORTABILITY_WARNING
|
#ifndef SIMDJSON_NO_PORTABILITY_WARNING
|
||||||
#pragma message("The simdjson library is designed \
|
// In the future, we should allow programmers
|
||||||
for 64-bit processors and it seems that you are not \
|
// to get warning.
|
||||||
compiling for a known 64-bit platform. All fast kernels \
|
|
||||||
will be disabled and performance may be poor. Please \
|
|
||||||
use a 64-bit target such as x64, 64-bit ARM or 64-bit PPC.")
|
|
||||||
#endif // SIMDJSON_NO_PORTABILITY_WARNING
|
#endif // SIMDJSON_NO_PORTABILITY_WARNING
|
||||||
#endif // SIMDJSON_IS_32BITS
|
#endif // SIMDJSON_IS_32BITS
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#define SIMDJSON_SIMDJSON_VERSION_H
|
#define SIMDJSON_SIMDJSON_VERSION_H
|
||||||
|
|
||||||
/** The version of simdjson being used (major.minor.revision) */
|
/** The version of simdjson being used (major.minor.revision) */
|
||||||
#define SIMDJSON_VERSION "3.3.0"
|
#define SIMDJSON_VERSION "3.4.0"
|
||||||
|
|
||||||
namespace simdjson {
|
namespace simdjson {
|
||||||
enum {
|
enum {
|
||||||
@@ -15,7 +15,7 @@ enum {
|
|||||||
/**
|
/**
|
||||||
* The minor version (major.MINOR.revision) of simdjson being used.
|
* The minor version (major.MINOR.revision) of simdjson being used.
|
||||||
*/
|
*/
|
||||||
SIMDJSON_VERSION_MINOR = 3,
|
SIMDJSON_VERSION_MINOR = 4,
|
||||||
/**
|
/**
|
||||||
* The revision (major.minor.REVISION) of simdjson being used.
|
* The revision (major.minor.REVISION) of simdjson being used.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* auto-generated on . Do not edit! */
|
/* auto-generated on 2023-10-25 19:34:52 -0400. Do not edit! */
|
||||||
/* including simdjson.cpp: */
|
/* including simdjson.cpp: */
|
||||||
/* begin file simdjson.cpp */
|
/* begin file simdjson.cpp */
|
||||||
#define SIMDJSON_SRC_SIMDJSON_CPP
|
#define SIMDJSON_SRC_SIMDJSON_CPP
|
||||||
@@ -131,11 +131,8 @@
|
|||||||
|
|
||||||
#if SIMDJSON_IS_32BITS
|
#if SIMDJSON_IS_32BITS
|
||||||
#ifndef SIMDJSON_NO_PORTABILITY_WARNING
|
#ifndef SIMDJSON_NO_PORTABILITY_WARNING
|
||||||
#pragma message("The simdjson library is designed \
|
// In the future, we should allow programmers
|
||||||
for 64-bit processors and it seems that you are not \
|
// to get warning.
|
||||||
compiling for a known 64-bit platform. All fast kernels \
|
|
||||||
will be disabled and performance may be poor. Please \
|
|
||||||
use a 64-bit target such as x64, 64-bit ARM or 64-bit PPC.")
|
|
||||||
#endif // SIMDJSON_NO_PORTABILITY_WARNING
|
#endif // SIMDJSON_NO_PORTABILITY_WARNING
|
||||||
#endif // SIMDJSON_IS_32BITS
|
#endif // SIMDJSON_IS_32BITS
|
||||||
|
|
||||||
|
|||||||
+572
-33
File diff suppressed because it is too large
Load Diff
@@ -51,6 +51,10 @@ namespace document_tests {
|
|||||||
simdjson::dom::array array;
|
simdjson::dom::array array;
|
||||||
ASSERT_SUCCESS( parser.parse(smalljson).get(array) );
|
ASSERT_SUCCESS( parser.parse(smalljson).get(array) );
|
||||||
ASSERT_EQUAL( array.size(), 3 );
|
ASSERT_EQUAL( array.size(), 3 );
|
||||||
|
ASSERT_EQUAL( *array.begin() < *array.end(), true );
|
||||||
|
ASSERT_EQUAL( *array.end() < *array.begin(), false );
|
||||||
|
ASSERT_EQUAL( *array.begin() == *array.begin(), true );
|
||||||
|
ASSERT_EQUAL( *array.begin() == *array.end(), false );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool count_object_example() {
|
bool count_object_example() {
|
||||||
@@ -60,6 +64,10 @@ namespace document_tests {
|
|||||||
simdjson::dom::object object;
|
simdjson::dom::object object;
|
||||||
ASSERT_SUCCESS( parser.parse(smalljson).get(object) );
|
ASSERT_SUCCESS( parser.parse(smalljson).get(object) );
|
||||||
ASSERT_EQUAL( object.size(), 3 );
|
ASSERT_EQUAL( object.size(), 3 );
|
||||||
|
ASSERT_EQUAL( (*object.begin()).value < (*object.end()).value, true );
|
||||||
|
ASSERT_EQUAL( (*object.end()).value < (*object.begin()).value, false );
|
||||||
|
ASSERT_EQUAL( (*object.begin()).value == (*object.begin()).value, true );
|
||||||
|
ASSERT_EQUAL( (*object.begin()).value == (*object.end()).value, false );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool padded_with_open_bracket() {
|
bool padded_with_open_bracket() {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ add_cpp_test(ondemand_ordering_tests LABELS ondemand acceptance per_impl
|
|||||||
add_cpp_test(ondemand_parse_api_tests LABELS ondemand acceptance per_implementation)
|
add_cpp_test(ondemand_parse_api_tests LABELS ondemand acceptance per_implementation)
|
||||||
add_cpp_test(ondemand_readme_examples LABELS ondemand acceptance per_implementation)
|
add_cpp_test(ondemand_readme_examples LABELS ondemand acceptance per_implementation)
|
||||||
add_cpp_test(ondemand_scalar_tests LABELS ondemand acceptance per_implementation)
|
add_cpp_test(ondemand_scalar_tests LABELS ondemand acceptance per_implementation)
|
||||||
|
add_cpp_test(ondemand_to_string LABELS ondemand acceptance per_implementation)
|
||||||
add_cpp_test(ondemand_twitter_tests LABELS ondemand acceptance per_implementation)
|
add_cpp_test(ondemand_twitter_tests LABELS ondemand acceptance per_implementation)
|
||||||
add_cpp_test(ondemand_wrong_type_error_tests LABELS ondemand acceptance per_implementation)
|
add_cpp_test(ondemand_wrong_type_error_tests LABELS ondemand acceptance per_implementation)
|
||||||
add_cpp_test(ondemand_iterate_many_csv LABELS ondemand acceptance per_implementation)
|
add_cpp_test(ondemand_iterate_many_csv LABELS ondemand acceptance per_implementation)
|
||||||
|
|||||||
@@ -144,14 +144,20 @@ namespace parse_api_tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::string json = "12";
|
std::string json = "12345642314123421321321321321321312321321321321312";
|
||||||
json.shrink_to_fit();
|
json.shrink_to_fit();
|
||||||
cout << "- string, 0 padding" << endl;
|
cout << "- string, 0 padding" << endl;
|
||||||
ASSERT_ERROR( parser.iterate(json), INSUFFICIENT_PADDING );
|
ASSERT_SUCCESS( parser.iterate(json) );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::string json = "12345642314123421321321321321321312321321321321312";
|
||||||
|
json.shrink_to_fit();
|
||||||
|
cout << "- string, 0 padding" << endl;
|
||||||
|
ASSERT_ERROR( parser.iterate((const std::string&)json), INSUFFICIENT_PADDING );
|
||||||
// It's actually kind of hard to allocate "just enough" capacity, since the string tends
|
// It's actually kind of hard to allocate "just enough" capacity, since the string tends
|
||||||
// to grow more than you tell it to.
|
// to grow more than you tell it to.
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_SUCCEED();
|
TEST_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,39 @@ bool string2() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool to_string_example_no_except() {
|
||||||
|
TEST_START();
|
||||||
|
auto json = R"({
|
||||||
|
"name": "Daniel",
|
||||||
|
"age": 42
|
||||||
|
})"_padded;
|
||||||
|
ondemand::parser parser;
|
||||||
|
ondemand::document doc;
|
||||||
|
auto err = parser.iterate(json).get(doc);
|
||||||
|
if(err) { return false; }
|
||||||
|
std::string name;
|
||||||
|
err = doc["name"].get_string(name);
|
||||||
|
if(err) { return false; }
|
||||||
|
TEST_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
#if SIMDJSON_EXCEPTIONS
|
#if SIMDJSON_EXCEPTIONS
|
||||||
|
|
||||||
|
|
||||||
|
bool to_string_example() {
|
||||||
|
TEST_START();
|
||||||
|
auto json = R"({
|
||||||
|
"name": "Daniel",
|
||||||
|
"age": 42
|
||||||
|
})"_padded;
|
||||||
|
ondemand::parser parser;
|
||||||
|
ondemand::document doc = parser.iterate(json);
|
||||||
|
std::string name;
|
||||||
|
doc["name"].get_string(name);
|
||||||
|
ASSERT_EQUAL(name, "Daniel");
|
||||||
|
TEST_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
bool gen_raw1() {
|
bool gen_raw1() {
|
||||||
TEST_START();
|
TEST_START();
|
||||||
simdjson::ondemand::parser parser;
|
simdjson::ondemand::parser parser;
|
||||||
@@ -141,6 +173,76 @@ bool examplecrt() {
|
|||||||
TEST_SUCCEED();
|
TEST_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool examplecrt_realloc() {
|
||||||
|
TEST_START();
|
||||||
|
std::string unpadded_input_json = R"([
|
||||||
|
{ "monitor": [
|
||||||
|
{ "id": "monitor", "type": "toggle", "label": "monitor" },
|
||||||
|
{ "id": "profile", "type": "selector", "label": "collection" },
|
||||||
|
{ "id": "overlay", "type": "selector", "label": "overlay" },
|
||||||
|
{ "id": "zoom", "type": "toggleSlider", "label": "zoom" }
|
||||||
|
] },
|
||||||
|
|
||||||
|
{ "crt": [
|
||||||
|
{ "id": "system", "type": "multi", "label": "system", "choices": "PAL, NTSC" },
|
||||||
|
{ "type": "spacer" },
|
||||||
|
{ "id": "brightness", "type": "slider", "icon": "brightness" },
|
||||||
|
{ "id": "contrast", "type": "slider", "icon": "contrast" },
|
||||||
|
{ "id": "saturation", "type": "slider", "icon": "saturation" },
|
||||||
|
{ "type": "spacer" },
|
||||||
|
{ "id": "overscan", "type": "toggleSlider", "label": "overscan" },
|
||||||
|
{ "type": "spacer" },
|
||||||
|
{ "id": "emulation", "type": "toggle", "label": "CRT emulation" },
|
||||||
|
{ "type": "spacer" },
|
||||||
|
{ "id": "curve", "type": "toggleSlider", "label": "curve" },
|
||||||
|
{ "id": "bleed", "type": "toggleSlider", "label": "bleed" },
|
||||||
|
{ "id": "vignette", "type": "toggleSlider", "label": "vignette" },
|
||||||
|
{ "id": "scanlines", "type": "toggleSlider", "label": "scanlines" },
|
||||||
|
{ "id": "gridlines", "type": "toggleSlider", "label": "gridlines" },
|
||||||
|
{ "id": "glow", "type": "toggleSlider", "label": "glow" },
|
||||||
|
{ "id": "flicker", "type": "toggleSlider", "label": "flicker" },
|
||||||
|
{ "id": "noise", "type": "toggleSlider", "label": "noise" },
|
||||||
|
{}
|
||||||
|
] }
|
||||||
|
])";
|
||||||
|
unpadded_input_json.shrink_to_fit();
|
||||||
|
auto parser = ondemand::parser{};
|
||||||
|
auto doc = parser.iterate(unpadded_input_json);
|
||||||
|
auto root_array = doc.get_array();
|
||||||
|
// the root should be an object, not an array, but that's the JSON we are
|
||||||
|
// given.
|
||||||
|
for (ondemand::object node : root_array) {
|
||||||
|
// We know that we are going to have just one element in the object.
|
||||||
|
for (auto field : node) {
|
||||||
|
std::cout << "\n\ntop level:" << field.key() << std::endl;
|
||||||
|
// You can get a proper std::string_view for the key with:
|
||||||
|
// std::string_view key = field.unescaped_key();
|
||||||
|
// and second for-range loop to get child-elements here
|
||||||
|
for (ondemand::object inner_object : field.value()) {
|
||||||
|
auto i = inner_object.begin();
|
||||||
|
if (i == inner_object.end()) {
|
||||||
|
std::cout << "empty object" << std::endl;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
for (; i != inner_object.end(); ++i) {
|
||||||
|
auto inner_field = *i;
|
||||||
|
std::cout << '"' << inner_field.key()
|
||||||
|
<< "\" : " << inner_field.value() << ", ";
|
||||||
|
// You can get proper std::string_view for the key and value with:
|
||||||
|
// std::string_view inner_key = field.unescaped_key();
|
||||||
|
// std::string_view value_str = field.value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
// You can break here if you only want just the first element.
|
||||||
|
// break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TEST_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
bool number_tests() {
|
bool number_tests() {
|
||||||
TEST_START();
|
TEST_START();
|
||||||
ondemand::parser parser;
|
ondemand::parser parser;
|
||||||
@@ -1420,11 +1522,14 @@ bool run() {
|
|||||||
&& current_location_user_error()
|
&& current_location_user_error()
|
||||||
&& current_location_out_of_bounds()
|
&& current_location_out_of_bounds()
|
||||||
&& current_location_no_error()
|
&& current_location_no_error()
|
||||||
|
&& to_string_example_no_except()
|
||||||
#if SIMDJSON_EXCEPTIONS
|
#if SIMDJSON_EXCEPTIONS
|
||||||
|
&& to_string_example()
|
||||||
&& raw_string()
|
&& raw_string()
|
||||||
&& number_tests()
|
&& number_tests()
|
||||||
&& current_location_tape_error_with_except()
|
&& current_location_tape_error_with_except()
|
||||||
&& examplecrt()
|
&& examplecrt()
|
||||||
|
&& examplecrt_realloc()
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,210 @@
|
|||||||
|
#include "simdjson.h"
|
||||||
|
#include "test_ondemand.h"
|
||||||
|
|
||||||
|
using namespace simdjson;
|
||||||
|
|
||||||
|
namespace json_package_tests {
|
||||||
|
using namespace std;
|
||||||
|
bool baby() {
|
||||||
|
TEST_START();
|
||||||
|
auto json = R"({
|
||||||
|
"name": "Daniel",
|
||||||
|
"age": 42
|
||||||
|
})"_padded;
|
||||||
|
ondemand::parser parser;
|
||||||
|
ondemand::document doc;
|
||||||
|
ASSERT_SUCCESS(parser.iterate(json).get(doc));
|
||||||
|
|
||||||
|
simdjson::ondemand::object main_object;
|
||||||
|
ASSERT_SUCCESS(doc.get_object().get(main_object));
|
||||||
|
std::string name;
|
||||||
|
ASSERT_SUCCESS(main_object["name"].get_string(name));
|
||||||
|
ASSERT_EQUAL(name, "Daniel");
|
||||||
|
uint64_t age;
|
||||||
|
ASSERT_SUCCESS(main_object["age"].get_uint64().get(age));
|
||||||
|
ASSERT_EQUAL(age, 42);
|
||||||
|
TEST_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool thirtysecondsofcode() {
|
||||||
|
TEST_START();
|
||||||
|
auto json = R"({
|
||||||
|
"name": "30-seconds-of-code",
|
||||||
|
"private": true,
|
||||||
|
"version": "10.0.0",
|
||||||
|
"description": "30 seconds of code website.",
|
||||||
|
"exports": "./index.js",
|
||||||
|
"author": "chalarangelo",
|
||||||
|
"type": "module",
|
||||||
|
"devDependencies": {
|
||||||
|
"@jsiqle/core": "^3.0.0",
|
||||||
|
"astro": "^3.2.0",
|
||||||
|
"chalk": "^5.3.0",
|
||||||
|
"eslint": "^8.50.0",
|
||||||
|
"eslint-config-prettier": "^9.0.0",
|
||||||
|
"front-matter": "^4.0.2",
|
||||||
|
"fs-extra": "^11.1.1",
|
||||||
|
"glob": "^10.3.10",
|
||||||
|
"hast-util-to-html": "^9.0.0",
|
||||||
|
"js-yaml": "^4.1.0",
|
||||||
|
"mdast-util-to-hast": "^13.0.2",
|
||||||
|
"prettier": "^3.0.3",
|
||||||
|
"prettier-plugin-astro": "^0.12.0",
|
||||||
|
"prismjs": "^1.29.0",
|
||||||
|
"remark": "^15.0.1",
|
||||||
|
"remark-gfm": "^4.0.0",
|
||||||
|
"sass": "^1.68.0",
|
||||||
|
"sharp": "^0.32.6",
|
||||||
|
"unist-util-select": "^5.0.0",
|
||||||
|
"unist-util-visit": "^5.0.0",
|
||||||
|
"unist-util-visit-parents": "^6.0.1",
|
||||||
|
"webfonts-generator": "^0.4.0"
|
||||||
|
},
|
||||||
|
"imports": {
|
||||||
|
"#blocks/*": "./src/blocks/*.js",
|
||||||
|
"#components/*": "./src/components/*.astro",
|
||||||
|
"#layouts/*": "./src/layouts/*.astro",
|
||||||
|
"#settings/*": "./src/settings/*.js",
|
||||||
|
"#prefabs": "./src/prefabs/index.js",
|
||||||
|
"#utils": "./src/utils/index.js",
|
||||||
|
"#utils/search": "./src/utils/search.js"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"predev": "NODE_ENV=development node ./src/scripts/develop.js",
|
||||||
|
"dev": "astro dev --port 8000",
|
||||||
|
"start": "astro dev --port 8000",
|
||||||
|
"prebuild": "NODE_ENV=production node ./src/scripts/build.js",
|
||||||
|
"build": "astro build",
|
||||||
|
"preview": "astro preview --port 9000",
|
||||||
|
"watch": "NODE_ENV=development node ./src/scripts/watch.js",
|
||||||
|
"console": "NODE_ENV=production node ./src/scripts/console.js",
|
||||||
|
"create": "NODE_ENV=production node ./src/scripts/create.js",
|
||||||
|
"icons": "NODE_ENV=production node ./src/scripts/icons.js",
|
||||||
|
"manifest": "NODE_ENV=production node ./src/scripts/manifest.js"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/30-seconds/30-seconds-of-code"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/30-seconds/30-seconds-of-code/issues"
|
||||||
|
},
|
||||||
|
"browserslist": [
|
||||||
|
"> 0.5% and last 4 versions and not dead and not ie>0 and not op_mini all and not and_uc>0 and not edge<79"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18.14.2"
|
||||||
|
}
|
||||||
|
})"_padded;
|
||||||
|
ondemand::parser parser;
|
||||||
|
ondemand::document doc;
|
||||||
|
ASSERT_SUCCESS(parser.iterate(json).get(doc));
|
||||||
|
|
||||||
|
simdjson::ondemand::object main_object;
|
||||||
|
ASSERT_SUCCESS(doc.get_object().get(main_object));
|
||||||
|
|
||||||
|
simdjson::ondemand::raw_json_string key;
|
||||||
|
simdjson::ondemand::value value;
|
||||||
|
|
||||||
|
for (auto field : main_object) {
|
||||||
|
// Throw error if getting key or value fails.
|
||||||
|
ASSERT_SUCCESS(field.key().get(key));
|
||||||
|
ASSERT_SUCCESS(field.value().get(value));
|
||||||
|
|
||||||
|
if (key == "name") {
|
||||||
|
std::string name;
|
||||||
|
ASSERT_SUCCESS(value.get_string(name));
|
||||||
|
ASSERT_EQUAL(name, "30-seconds-of-code");
|
||||||
|
} else if (key == "main") {
|
||||||
|
std::string main;
|
||||||
|
ASSERT_SUCCESS(value.get_string(main));
|
||||||
|
// unused
|
||||||
|
} else if (key == "exports") {
|
||||||
|
simdjson::ondemand::json_type exports_type;
|
||||||
|
if (!value.type().get(exports_type)) {
|
||||||
|
std::string_view exports;
|
||||||
|
switch (exports_type) {
|
||||||
|
case simdjson::ondemand::json_type::object: {
|
||||||
|
simdjson::ondemand::object exports_object;
|
||||||
|
if (!value.get_object().get(exports_object) &&
|
||||||
|
!exports_object.raw_json().get(exports)) {
|
||||||
|
// unused
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case simdjson::ondemand::json_type::array: {
|
||||||
|
simdjson::ondemand::array exports_array;
|
||||||
|
if (!value.get_array().get(exports_array) &&
|
||||||
|
!exports_array.raw_json().get(exports)) {
|
||||||
|
// unused
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case simdjson::ondemand::json_type::string: {
|
||||||
|
if (!value.get_string().get(exports)) {
|
||||||
|
ASSERT_EQUAL(exports, "./index.js");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (key == "imports") {
|
||||||
|
simdjson::ondemand::json_type imports_type;
|
||||||
|
if (!value.type().get(imports_type)) {
|
||||||
|
std::string_view imports;
|
||||||
|
switch (imports_type) {
|
||||||
|
case simdjson::ondemand::json_type::object: {
|
||||||
|
simdjson::ondemand::object imports_object;
|
||||||
|
if (!value.get_object().get(imports_object) &&
|
||||||
|
!imports_object.raw_json().get(imports)) {
|
||||||
|
ASSERT_EQUAL(imports, R"({
|
||||||
|
"#blocks/*": "./src/blocks/*.js",
|
||||||
|
"#components/*": "./src/components/*.astro",
|
||||||
|
"#layouts/*": "./src/layouts/*.astro",
|
||||||
|
"#settings/*": "./src/settings/*.js",
|
||||||
|
"#prefabs": "./src/prefabs/index.js",
|
||||||
|
"#utils": "./src/utils/index.js",
|
||||||
|
"#utils/search": "./src/utils/search.js"
|
||||||
|
})");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case simdjson::ondemand::json_type::array: {
|
||||||
|
simdjson::ondemand::array imports_array;
|
||||||
|
if (!value.get_array().get(imports_array) &&
|
||||||
|
!imports_array.raw_json().get(imports)) {
|
||||||
|
// unused
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case simdjson::ondemand::json_type::string: {
|
||||||
|
if (!value.get_string().get(imports)) {
|
||||||
|
// unused
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (key == "type") {
|
||||||
|
std::string_view type;
|
||||||
|
if (!value.get_string().get(type) &&
|
||||||
|
(type == "commonjs" || type == "module")) {
|
||||||
|
ASSERT_EQUAL(type, "module");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
TEST_SUCCEED();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool run() { return thirtysecondsofcode() && baby(); }
|
||||||
|
|
||||||
|
} // namespace json_package_tests
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
return test_main(argc, argv, json_package_tests::run);
|
||||||
|
}
|
||||||
@@ -167,8 +167,6 @@ print("the commandline is {}".format(cp.args))
|
|||||||
if(cp.returncode != 0):
|
if(cp.returncode != 0):
|
||||||
print("Failed to run doxygen")
|
print("Failed to run doxygen")
|
||||||
|
|
||||||
#ipe = subprocess.Popen(["doxygen"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=maindir)
|
|
||||||
#doxygenresult = pipe.communicate()[0].decode().strip()
|
|
||||||
|
|
||||||
pattern = re.compile("https://simdjson.org/api/(\d+\.\d+\.\d+)/index.html")
|
pattern = re.compile("https://simdjson.org/api/(\d+\.\d+\.\d+)/index.html")
|
||||||
readmefile = maindir + os.sep + "README.md"
|
readmefile = maindir + os.sep + "README.md"
|
||||||
|
|||||||
Reference in New Issue
Block a user