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>
37 template<
typename JsonElement =
json_value,
auto... PolicyFlags>
40 options::details::make_parse_flags<PolicyFlags...>( ).value>>;
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 );
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( );
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;
158 return std::string_view( m_state.first, m_state.size( ) );
166 template<
typename JsonElement =
json_value,
auto... PolicyFlags>
169 options::details::make_parse_flags<PolicyFlags...>( ).value>>;
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
constexpr void operator++(int) &
Move the parse state to the next element.
constexpr bool good() const
Is it ok to dereference iterator.
json_details::arrow_proxy< value_type > pointer
json_lines_iterator()=default
constexpr value_type operator*() const
Parse the current element.
TryDefaultParsePolicy< BasicParsePolicy< options::details::make_parse_flags< PolicyFlags... >().value > > ParseState
constexpr bool operator==(json_lines_iterator const &rhs) const
Compare rhs for equivalence.
constexpr std::string_view get_raw_json_document() const
json_details::json_result_t< element_type > value_type
constexpr json_lines_iterator(daw::string_view json_lines_doc)
std::ptrdiff_t difference_type
constexpr pointer operator->() const
A dereferencable value proxy holding the result of operator* . This is for compatibility with the Ite...
typename ParseState::CharT CharT
constexpr bool operator!=(json_lines_iterator const &rhs) const
Check if the other iterator is not equivalent.
constexpr json_lines_iterator & operator++()
Move the parse state to the next element.
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.
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...
daw::conditional_t< ParsePolicy::is_default_parse_policy, DefaultParsePolicy, ParsePolicy > TryDefaultParsePolicy
Customization point traits.
A range of json_lines_iterators.
constexpr iterator begin() const
typename ParsePolicy::CharT CharT
constexpr json_lines_range(iterator first, iterator last=iterator())
TryDefaultParsePolicy< BasicParsePolicy< options::details::make_parse_flags< PolicyFlags... >().value > > ParsePolicy
constexpr json_lines_range(daw::string_view json_lines_doc)
json_lines_range()=default
constexpr iterator end() const
constexpr bool empty() const
Are there any elements in range.
Handles the bounds and policy items for parsing execution and comments.
A non-owning container for arbitrary JSON values that allows movement/iteration through.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.