1 #ifndef SIMDJSON_GENERIC_ONDEMAND_FIELD_INL_H
3 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
4 #define SIMDJSON_GENERIC_ONDEMAND_FIELD_INL_H
5 #include "simdjson/generic/ondemand/base.h"
6 #include "simdjson/generic/ondemand/field.h"
7 #include "simdjson/generic/ondemand/value-inl.h"
8 #include "simdjson/generic/ondemand/value_iterator-inl.h"
12 namespace SIMDJSON_IMPLEMENTATION {
19 : std::pair<raw_json_string, ondemand::value>(key, std::forward<ondemand::value>(
value))
25 SIMDJSON_TRY( parent_iter.field_key().get(key) );
26 SIMDJSON_TRY( parent_iter.field_value() );
27 return field::start(parent_iter, key);
30 simdjson_inline
simdjson_result<field> field::start(
const value_iterator &parent_iter, raw_json_string key) noexcept {
31 return field(key, parent_iter.child());
35 SIMDJSON_ASSUME(first.buf !=
nullptr);
41 template <
typename string_type>
44 SIMDJSON_TRY( unescaped_key(allow_replacement).get(key) );
50 SIMDJSON_ASSUME(first.buf !=
nullptr);
56 SIMDJSON_ASSUME(first.buf !=
nullptr);
57 return std::string_view(
reinterpret_cast<const char*
>(first.buf-1), second.iter._json_iter->token.peek(-1) - first.buf + 1);
61 SIMDJSON_ASSUME(first.buf !=
nullptr);
62 auto end_quote = second.iter._json_iter->token.peek(-1);
63 while(*end_quote !=
'"') end_quote--;
64 return std::string_view(
reinterpret_cast<const char*
>(first.buf), end_quote - first.buf);
72 return std::forward<field>(*this).second;
81 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field>::simdjson_result(
82 SIMDJSON_IMPLEMENTATION::ondemand::field &&value
84 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::field>(
85 std::forward<SIMDJSON_IMPLEMENTATION::ondemand::field>(value)
89 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field>::simdjson_result(
92 implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::field>(error)
96 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field>::key() noexcept {
101 simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field>::key_raw_json_token() noexcept {
103 return first.key_raw_json_token();
106 simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field>::escaped_key() noexcept {
108 return first.escaped_key();
111 simdjson_inline simdjson_result<std::string_view> simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field>::unescaped_key(
bool allow_replacement) noexcept {
112 if (error()) {
return error(); }
113 return first.unescaped_key(allow_replacement);
116 template<
typename string_type>
117 simdjson_inline
error_code simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::field>::unescaped_key(string_type &receiver,
bool allow_replacement) noexcept {
118 if (error()) {
return error(); }
119 return first.unescaped_key(receiver, allow_replacement);
124 return std::move(first.value());
simdjson_inline std::string_view key_raw_json_token() const noexcept
Get the unprocessed key as a string_view.
simdjson_inline simdjson_warn_unused simdjson_result< std::string_view > unescaped_key(bool allow_replacement=false) noexcept
Get the key as a string_view (for higher speed, consider raw_key).
simdjson_inline raw_json_string key() const noexcept
Get the key as a raw_json_string.
simdjson_inline std::string_view escaped_key() const noexcept
Get the key as a string_view.
simdjson_inline field() noexcept
Create a new invalid field.
simdjson_inline ondemand::value & value() &noexcept
Get the field value.
A string escaped per JSON rules, terminated with quote (").
An ephemeral JSON value returned during iteration.
The top level simdjson namespace, containing everything the library provides.
error_code
All possible errors returned by simdjson.
The result of a simdjson operation that could fail.
simdjson_inline error_code error() const noexcept
The error.
simdjson_inline T & value() &noexcept(false)
Get the result value.