 |
DAW JSON Link
|
Go to the documentation of this file.
18 #include <string_view>
26 template<
typename Range>
27 class basic_json_value;
33 template<
typename Range>
35 std::optional<std::string_view>
name;
39 template<std::
size_t Idx,
typename Range>
41 static_assert( Idx < 2 );
42 if constexpr( Idx == 0 ) {
49 template<std::
size_t Idx,
typename Range>
51 static_assert( Idx < 2 );
52 if constexpr( Idx == 0 ) {
59 template<std::
size_t Idx,
typename Range>
61 static_assert( Idx < 2 );
62 if constexpr( Idx == 0 ) {
63 return std::move( rng.name );
65 return std::move( rng.value );
71 template<
typename Range>
72 class tuple_element<0,
daw::json::basic_json_pair<Range>> {
74 using type = std::optional<std::string_view>;
77 template<
typename Range>
78 class tuple_element<1,
daw::json::basic_json_pair<Range>> {
83 template<
typename Range>
84 class tuple_size<
daw::json::basic_json_pair<Range>>
85 :
public std::integral_constant<std::size_t, 2> {};
93 template<
typename Range>
101 using pointer = json_details::arrow_proxy<value_type>;
111 friend class ::daw::json::basic_json_value<Range>;
120 constexpr std::optional<std::string_view>
name( )
const {
125 auto result = json_details::parse_name( rng );
126 return std::string_view( result.data( ), result.size( ) );
136 return Range( m_state );
139 (void)json_details::parse_name( rng );
140 return Range( rng.first, rng.last );
149 return { { }, Range( m_state.first, m_state.last ) };
152 auto name = json_details::parse_name( rng );
153 return { std::string_view(
name.data( ),
name.size( ) ),
154 Range( rng.first, rng.last ) };
174 (void)json_details::parse_name( m_state );
176 (void)json_details::skip_value( m_state );
177 m_state.clean_tail( );
197 return *m_state.class_first ==
'[';
205 return *m_state.class_first ==
'{';
213 if( not m_state.has_more( ) or m_state.is_null( ) ) {
216 switch( m_state.front( ) ) {
246 constexpr
explicit operator bool( )
const {
259 return m_state.first == rhs.m_state.first;
263 return not rhs.
good( );
277 template<
typename Range>
290 template<
typename Range>
299 template<
typename Range>
311 : m_rng( std::move( rng ) ) {
320 : m_rng( sv.data( ), sv.data( ) + sv.size( ) ) {}
327 : m_rng( first, first + static_cast<std::ptrdiff_t>( sz ) ) {}
334 : m_rng( first, last ) {}
340 [[nodiscard]]
inline constexpr Range
get_range( )
const {
350 Range rng = Range( m_rng.first, m_rng.last );
351 rng.remove_prefix( );
369 if( not m_rng.has_more( ) ) {
372 switch( m_rng.front( ) ) {
374 return JsonBaseParseTypes::String;
376 return JsonBaseParseTypes::Class;
378 return JsonBaseParseTypes::Array;
390 return JsonBaseParseTypes::Number;
392 if constexpr( not Range::is_unchecked_input ) {
393 if( m_rng.starts_with(
"true" ) ) {
394 return JsonBaseParseTypes::Bool;
398 return JsonBaseParseTypes::Bool;
401 if constexpr( not Range::is_unchecked_input ) {
402 if( m_rng.starts_with(
"false" ) ) {
403 return JsonBaseParseTypes::Bool;
407 return JsonBaseParseTypes::Bool;
411 ErrorReason::InvalidNull, m_rng );
412 return JsonBaseParseTypes::Null;
423 auto result = json_details::skip_value( rng );
428 return { result.first, result.size( ) };
435 template<
typename Allocator = std::allocator<
char>,
436 typename Traits = std::
char_traits<
char>>
437 std::basic_string<char, Traits, Allocator>
438 get_string( Allocator
const &alloc = std::allocator<char>( ) )
const {
440 auto result = json_details::skip_value( rng );
445 return { result.first, result.size( ), alloc };
453 return ( m_rng.starts_with(
"null" ) );
461 return m_rng.is_opening_brace_checked( );
469 return m_rng.is_opening_bracket_checked( );
477 if( not m_rng.has_more( ) ) {
480 switch( m_rng.front( ) ) {
503 return m_rng.is_quotes_checked( );
511 if( not m_rng.has_more( ) ) {
514 switch( m_rng.front( ) ) {
516 if constexpr( not Range::is_unchecked_input ) {
517 return m_rng ==
"true";
522 if constexpr( not Range::is_unchecked_input ) {
523 return m_rng ==
"false";
540 template<
typename NewRange>
542 auto new_range = NewRange( m_rng.first, m_rng.last );
543 new_range.class_first = m_rng.class_first;
544 new_range.class_last = m_rng.class_last;
Definition: daw_json_value.h:34
constexpr decltype(auto) get(basic_json_pair< Range > const &rng)
Definition: daw_json_value.h:40
iterator first
Definition: daw_json_value.h:280
Definition: daw_json_event_parser.h:17
#define daw_json_assert_weak(Bool,...)
Definition: daw_json_assert.h:206
constexpr basic_json_value(char const *first, std::size_t sz)
Definition: daw_json_value.h:325
constexpr pointer operator->()
Definition: daw_json_value.h:163
constexpr Range get_range() const
Definition: daw_json_value.h:340
JsonBaseParseTypes
Definition: daw_json_parse_common.h:379
std::optional< std::string_view > name
Definition: daw_json_value.h:35
static DAW_JSON_NOINLINE void daw_json_error(daw::json::ErrorReason reason)
Definition: daw_json_assert.h:59
constexpr std::optional< std::string_view > name() const
Definition: daw_json_value.h:120
constexpr basic_json_value(std::string_view sv)
Definition: daw_json_value.h:319
std::string_view key_type
Definition: daw_json_value.h:95
constexpr basic_json_value_iterator operator++(int)
Definition: daw_json_value.h:186
constexpr bool operator!=(basic_json_value_iterator< Range > const &rhs) const
Definition: daw_json_value.h:272
std::ptrdiff_t difference_type
Definition: daw_json_value.h:102
constexpr std::string_view get_string_view() const
Definition: daw_json_value.h:421
constexpr iterator begin() const
Definition: daw_json_value.h:349
Definition: daw_json_value.h:300
constexpr bool operator==(basic_json_value_iterator< Range > const &rhs) const
Definition: daw_json_value.h:256
constexpr bool is_class() const
Definition: daw_json_value.h:204
constexpr bool is_bool() const
Definition: daw_json_value.h:510
std::forward_iterator_tag iterator_category
Definition: daw_json_value.h:103
iterator last
Definition: daw_json_value.h:281
constexpr basic_json_value_iterator & operator++()
Definition: daw_json_value.h:171
constexpr bool is_null() const
Definition: daw_json_value.h:452
constexpr basic_json_value_iterator()=default
constexpr basic_json_value(char const *first, char const *last)
Definition: daw_json_value.h:332
basic_json_value_iterator_range(basic_json_value_iterator< Range >, basic_json_value_iterator< Range >) -> basic_json_value_iterator_range< Range >
JsonBaseParseTypes type() const
Definition: daw_json_value.h:368
constexpr basic_json_value(Range rng)
Definition: daw_json_value.h:310
Definition: daw_json_event_parser.h:17
constexpr iterator begin()
Definition: daw_json_value.h:283
basic_json_value< Range > value
Definition: daw_json_value.h:36
json_details::arrow_proxy< value_type > pointer
Definition: daw_json_value.h:101
Definition: daw_json_value.h:278
constexpr bool good() const
Definition: daw_json_value.h:212
constexpr bool is_string() const
Definition: daw_json_value.h:502
constexpr basic_json_pair< Range > operator*()
Definition: daw_json_value.h:147
constexpr bool is_array() const
Definition: daw_json_value.h:468
constexpr iterator end() const
Definition: daw_json_value.h:360
constexpr bool is_array() const
Definition: daw_json_value.h:196
Definition: daw_json_value.h:94
basic_json_pair< Range > value_type
Definition: daw_json_value.h:99
constexpr basic_json_value< Range > value() const
Definition: daw_json_value.h:134
std::basic_string< char, Traits, Allocator > get_string(Allocator const &alloc=std::allocator< char >()) const
Definition: daw_json_value.h:438
constexpr bool is_unknown() const
Definition: daw_json_value.h:536
constexpr iterator end()
Definition: daw_json_value.h:286
constexpr bool is_class() const
Definition: daw_json_value.h:460
constexpr bool is_number() const
Definition: daw_json_value.h:476