17 #include <daw/daw_cxmath.h>
18 #include <daw/daw_move.h>
19 #include <daw/daw_scope_guard.h>
20 #include <daw/daw_traits.h>
21 #include <daw/daw_utility.h>
29 #include <string_view>
30 #include <type_traits>
37 template<
typename JsonElement =
json_value,
auto... PolicyFlags>
41 using CharT =
typename ParseState::CharT;
45 static_assert( not std::is_same_v<element_type, void>,
46 "Unknown JsonElement type." );
47 using value_type = json_details::json_result_t<element_type>;
49 using pointer = json_details::arrow_proxy<value_type>;
60 mutable CharT *m_can_skip =
nullptr;
67 daw::data_end( json_lines_doc ) ) ) {
77 ErrorReason::UnexpectedEndOfData, m_state );
80 auto const run_after_parse = daw::on_scope_exit( [&] {
81 m_can_skip = tmp.first;
83 (void)run_after_parse;
85 element_type::expected_type>( tmp );
93 [[nodiscard]] constexpr
pointer operator->( )
const {
101 ErrorReason::UnexpectedEndOfData, m_state );
103 m_state.first = m_can_skip;
104 m_can_skip =
nullptr;
106 (void)json_details::skip_known_value<element_type>( m_state );
108 m_state.move_next_member_or_end( );
113 constexpr
void operator++(
int ) & {
119 [[nodiscard]] constexpr
bool good( )
const {
120 return not m_state.is_null( ) and m_state.has_more( );
125 [[nodiscard]]
explicit constexpr
operator bool( )
const {
132 [[nodiscard]] constexpr
bool
140 return ( m_state.first == rhs.
m_state.first );
146 [[nodiscard]] constexpr
bool
149 return static_cast<bool>( rhs );
154 return m_state.first != rhs.
m_state.first;
157 constexpr std::string_view get_raw_json_document( )
const {
158 return std::string_view( m_state.first, m_state.size( ) );
166 template<
typename JsonElement =
json_value,
auto... PolicyFlags>
171 using CharT =
typename ParsePolicy::CharT;
186 : m_first( json_lines_doc ) {}
200 [[nodiscard]] constexpr
bool empty( )
const {
201 return m_first == m_last;
206 template<
typename JsonElement,
auto... PolicyFlags>
214 template<
typename JsonElement =
json_value,
auto... ParsePolicies>
217 daw::string_view jsonl_doc ) {
220 if( num_partitions <= 1 ) {
224 auto approx_segsize = jsonl_doc.size( ) / num_partitions;
225 auto result = result_t{ };
226 char const *
const last = daw::data_end( jsonl_doc );
227 while( not jsonl_doc.empty( ) ) {
228 char const *tmp = std::data( jsonl_doc ) + approx_segsize;
230 result.emplace_back( jsonl_doc );
233 while( tmp < last and *tmp !=
'\n' ) {
239 auto sz =
static_cast<std::size_t
>( tmp - std::data( jsonl_doc ) );
240 auto doc = jsonl_doc.pop_front( sz );
242 if( not doc.empty( ) ) {
243 result.emplace_back( doc );
Iterator for iterating over JSON array's.
json_details::json_deduced_type< JsonElement > element_type
json_details::arrow_proxy< value_type > pointer
json_lines_iterator()=default
TryDefaultParsePolicy< BasicParsePolicy< options::details::make_parse_flags< PolicyFlags... >().value > > ParseState
constexpr bool operator==(json_lines_iterator const &rhs) const
Compare rhs for equivalence.
json_details::json_result_t< element_type > value_type
std::ptrdiff_t difference_type
typename ParseState::CharT CharT
constexpr bool operator!=(json_lines_iterator const &rhs) const
Check if the other iterator is not equivalent.
std::input_iterator_tag iterator_category
#define daw_json_assert_weak(Bool,...)
Assert that Bool is true when in Checked Input mode If false pass rest of args to daw_json_error.
json_lines_range(daw::string_view) -> json_lines_range<>
std::vector< json_lines_range< JsonElement, ParsePolicies... > > partition_jsonl_document(std::size_t num_partitions, daw::string_view jsonl_doc)
parition the jsonl/nbjson document into num_partition non overlapping sub-ranges. This can be used to...
json_lines_iterator(daw::string_view) -> json_lines_iterator<>
DAW_CONSTEVAL auto make_parse_flags()
daw::conditional_t< ParsePolicy::is_default_parse_policy, DefaultParsePolicy, ParsePolicy > TryDefaultParsePolicy
basic_json_value<> json_value
An untyped JSON value.
Customization point traits.
A range of json_lines_iterators.
typename ParsePolicy::CharT CharT
TryDefaultParsePolicy< BasicParsePolicy< options::details::make_parse_flags< PolicyFlags... >().value > > ParsePolicy
json_lines_range()=default
Handles the bounds and policy items for parsing execution and comments.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.