16#include <daw/daw_algorithm.h>
17#include <daw/daw_move.h>
18#include <daw/daw_utility.h>
19#include <daw/iterator/daw_reverse_iterator.h>
32 [[nodiscard]]
inline std::vector<json_path_node>
34 char const *doc_start );
37 std::string_view m_name{ };
38 char const *m_value_start =
nullptr;
39 long long m_index = -1;
42 friend std::vector<json_path_node>
44 char const *doc_start );
48 long long Index,
char const *ValueStart )
50 , m_value_start( ValueStart )
61 [[nodiscard]]
constexpr std::string_view
name( )
const {
66 [[nodiscard]]
constexpr long long index( )
const {
80 [[nodiscard]]
inline std::string
82 return daw::algorithm::accumulate(
83 std::data( path_stack ), daw::data_end( path_stack ), std::string{ },
85 if( sv.index( ) >= 0 ) {
87 }
else if( not sv.name( ).empty( ) ) {
88 state +=
"." +
static_cast<std::string
>( sv.name( ) );
90 return DAW_FWD( state );
98 [[nodiscard]]
inline std::vector<json_path_node>
100 char const *doc_start ) {
101 if( parse_location ==
nullptr or doc_start ==
nullptr ) {
104 if( std::less<>{ }( parse_location, doc_start ) ) {
111 std::vector<json_path_node> parse_stack{ };
115 std::optional<json_path_node> last_popped{ };
119 if( parse_stack.empty( ) ) {
122 return parse_stack.back( ).type( );
126 if(
auto const range = jp.
value.get_raw_state( );
127 range.empty( ) or last <= std::data( range ) ) {
131 state.m_name = *jp.
name;
140 state.m_value_start = jp.
value.get_raw_state( ).first;
141 state.m_type = jp.
value.type( );
142 last_popped = std::nullopt;
147 parse_stack.push_back( state );
153 if( not parse_stack.empty( ) ) {
154 last_popped = parse_stack.back( );
155 state = parse_stack.back( );
156 parse_stack.pop_back( );
162 parse_stack.push_back( state );
168 if( not parse_stack.empty( ) ) {
169 last_popped = parse_stack.back( );
170 state = parse_stack.back( );
171 parse_stack.pop_back( );
177 auto sv = std::string_view( );
178#if defined( DAW_USE_EXCEPTIONS )
182#if defined( DAW_USE_EXCEPTIONS )
183 }
catch( json_exception
const & ) {
184 parse_stack.push_back( state );
188 if( std::data( sv ) <= last and last <= daw::data_end( sv ) ) {
189 parse_stack.push_back( state );
196 auto sv = std::string_view( );
197#if defined( DAW_USE_EXCEPTIONS )
201#if defined( DAW_USE_EXCEPTIONS )
202 }
catch( json_exception
const & ) {
203 parse_stack.push_back( state );
207 if( std::data( sv ) <= last and last <= daw::data_end( sv ) ) {
208 parse_stack.push_back( state );
215 auto sv = std::string_view( );
216#if defined( DAW_USE_EXCEPTIONS )
220#if defined( DAW_USE_EXCEPTIONS )
221 }
catch( json_exception
const & ) {
222 parse_stack.push_back( state );
226 if( std::data( sv ) <= last and last <= daw::data_end( sv ) ) {
227 parse_stack.push_back( state );
234 auto sv = std::string_view( );
235#if defined( DAW_USE_EXCEPTIONS )
239#if defined( DAW_USE_EXCEPTIONS )
240 }
catch( json_exception
const & ) {
241 parse_stack.push_back( state );
245 if( std::data( sv ) <= last and last <= daw::data_end( sv ) ) {
246 parse_stack.push_back( state );
251 } handler{ doc_start, parse_location + 1 };
253#if defined( DAW_USE_EXCEPTIONS )
257#if defined( DAW_USE_EXCEPTIONS )
258 }
catch( json_exception
const & ) {
263 if( handler.last_popped ) {
264 handler.parse_stack.push_back( *handler.last_popped );
266 return DAW_MOVE( handler.parse_stack );
269 [[nodiscard]]
inline std::vector<json_path_node>
271 char const *doc_start ) {
275 [[nodiscard]]
inline std::string
281 [[nodiscard]]
inline std::string
287 [[nodiscard]]
constexpr std::size_t
290 ErrorReason::UnexpectedEndOfData );
292 ErrorReason::UnexpectedEndOfData );
294 return daw::algorithm::accumulate( doc_start, doc_pos, std::size_t{ },
295 []( std::size_t count,
char c ) {
303 [[nodiscard]]
constexpr std::size_t
308 [[nodiscard]]
constexpr std::size_t
311 ErrorReason::UnexpectedEndOfData );
313 ErrorReason::UnexpectedEndOfData );
315 auto first = daw::reverse_iterator<char const *>( doc_pos );
316 auto last = daw::reverse_iterator<char const *>( doc_start );
318 std::distance( first, daw::algorithm::find( first, last,
'\n' ) );
320 return static_cast<std::size_t
>( pos );
323 [[nodiscard]]
constexpr std::size_t
Definition: daw_json_value.h:320
constexpr std::string_view get_string_view() const
Definition: daw_json_value.h:452
Definition: daw_json_find_path.h:36
constexpr JsonBaseParseTypes type() const
What type of value is represented.
Definition: daw_json_find_path.h:56
constexpr char const * value_start() const
The beginning of the value's data in JSON document.
Definition: daw_json_find_path.h:71
constexpr std::string_view name() const
The member name, only value for submembers of Class types.
Definition: daw_json_find_path.h:61
constexpr long long index() const
The element index, only valid for elements of Array types.
Definition: daw_json_find_path.h:66
friend std::vector< json_path_node > find_json_path_stack_to(char const *parse_location, char const *doc_start)
Get the json_path_nodes representing the path to the nearest value's position in the document.
Definition: daw_json_find_path.h:99
#define daw_json_assert(Bool,...)
Definition: daw_json_assert.h:179
constexpr handler_result_holder handle_on_null(Handler &&handler, basic_json_value< ParseState > &jv)
Definition: daw_json_event_parser.h:295
constexpr handler_result_holder handle_on_array_end(Handler &&handler)
Definition: daw_json_event_parser.h:218
constexpr handler_result_holder handle_on_string(Handler &&handler, basic_json_value< ParseState > &jv)
Definition: daw_json_event_parser.h:280
constexpr handler_result_holder handle_on_class_start(Handler &&handler, basic_json_value< ParseState > jv)
Definition: daw_json_event_parser.h:228
constexpr handler_result_holder handle_on_bool(Handler &&handler, basic_json_value< ParseState > jv)
Definition: daw_json_event_parser.h:266
constexpr handler_result_holder handle_on_class_end(Handler &&handler)
Definition: daw_json_event_parser.h:241
constexpr handler_result_holder handle_on_value(Handler &&handler, basic_json_pair< ParseState > p)
Definition: daw_json_event_parser.h:193
constexpr handler_result_holder handle_on_number(Handler &&handler, basic_json_value< ParseState > &jv)
Definition: daw_json_event_parser.h:251
constexpr handler_result_holder handle_on_array_start(Handler &&handler, basic_json_value< ParseState > jv)
Definition: daw_json_event_parser.h:205
constexpr std::string_view to_string(JsonBaseParseTypes pt)
Definition: daw_json_enums.h:63
std::string to_json_path_string(std::vector< json_path_node > const &path_stack)
Convert a json_path_node stack to a JSON Path string.
Definition: daw_json_find_path.h:81
constexpr std::size_t find_column_number_of(char const *doc_pos, char const *doc_start)
Definition: daw_json_find_path.h:309
constexpr std::size_t find_line_number_of(char const *doc_pos, char const *doc_start)
Definition: daw_json_find_path.h:288
JsonBaseParseTypes
The fundamental JSON types.
Definition: daw_json_enums.h:53
constexpr void json_event_parser(basic_json_value< ParseState > jvalue, Handler &&handler)
Definition: daw_json_event_parser.h:366
std::string find_json_path_to(char const *parse_location, char const *doc_start)
Definition: daw_json_find_path.h:276
std::vector< json_path_node > find_json_path_stack_to(char const *parse_location, char const *doc_start)
Get the json_path_nodes representing the path to the nearest value's position in the document.
Definition: daw_json_find_path.h:99
Definition: daw_from_json.h:22
Definition: daw_json_value.h:42
std::optional< std::string_view > name
Definition: daw_json_value.h:43
basic_json_value< ParseState > value
Definition: daw_json_value.h:44
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition: version.h:16