19 #include <daw/daw_attributes.h>
20 #include <daw/daw_function_table.h>
21 #include <daw/daw_likely.h>
22 #include <daw/daw_traits.h>
26 #include <type_traits>
31 template<
typename ParseState>
32 DAW_ATTRIB_FLATINLINE
static constexpr
void
34 if constexpr( ParseState::minified_document ) {
37 using CharT =
typename ParseState::CharT;
39 CharT *first = parse_state.first;
41 CharT *
const last = parse_state.last;
49 (
static_cast<unsigned>(
static_cast<unsigned char>( *first ) ) -
56 DAW_LIKELY( first < last ) and
57 (
static_cast<unsigned>(
static_cast<unsigned char>( *first ) ) -
62 parse_state.first = first;
66 template<
typename ParseState>
67 DAW_ATTRIB_FLATINLINE
static constexpr
void
69 if constexpr( ParseState::minified_document ) {
72 using CharT =
typename ParseState::CharT;
73 CharT *first = parse_state.first;
75 (
static_cast<unsigned>(
static_cast<unsigned char>( *first ) ) -
80 parse_state.first = first;
84 template<
typename ParseState>
85 DAW_ATTRIB_FLATINLINE
static constexpr
void
88 json_details::memchr_unchecked<
'"',
typename ParseState::exec_tag_t,
89 ParseState::expect_long_strings>(
90 parse_state.first, parse_state.last );
93 template<
char... keys,
typename ParseState>
94 DAW_ATTRIB_FLATINLINE
static constexpr
void
96 static_assert(
sizeof...( keys ) > 0 );
97 static_assert(
sizeof...( keys ) <= 16 );
99 using CharT =
typename ParseState::CharT;
101 if constexpr( daw::traits::not_same<
typename ParseState::exec_tag_t,
104 json_details::mempbrk<ParseState::is_unchecked_input,
105 typename ParseState::exec_tag_t,
106 ParseState::expect_long_strings, keys...>(
107 parse_state.first, parse_state.last );
109 CharT *first = parse_state.first;
110 CharT *
const last = parse_state.last;
118 ErrorReason::UnexpectedEndOfData,
120 while( not parse_policy_details::in<keys...>( *first ) ) {
127 first < last, ErrorReason::UnexpectedEndOfData, parse_state );
128 while( not parse_policy_details::in<keys...>( *first ) ) {
131 first < last, ErrorReason::UnexpectedEndOfData, parse_state );
134 parse_state.first = first;
138 DAW_ATTRIB_INLINE
static constexpr
bool is_literal_end(
char c ) {
139 return ( c ==
'\0' ) | ( c ==
',' ) | ( c ==
']' ) | ( c ==
'}' );
142 template<
char PrimLeft,
typename ParseState>
143 DAW_ATTRIB_FLATTEN
static constexpr ParseState
145 constexpr
char PrimRight = PrimLeft ==
'{' ?
'}' :
']';
146 constexpr
char SecLeft = PrimLeft ==
'{' ?
'[' :
'{';
147 constexpr
char SecRight = SecLeft ==
'{' ?
'}' :
']';
149 using CharT =
typename ParseState::CharT;
151 CharT *ptr_first = parse_state.first;
152 CharT *
const ptr_last = parse_state.last;
153 if( DAW_UNLIKELY( ptr_first >= ptr_last ) ) {
156 auto result = parse_state;
158 std::uint32_t prime_bracket_count = 1;
159 std::uint32_t second_bracket_count = 0;
161 if( *ptr_first == PrimLeft ) {
164 while( DAW_LIKELY( ptr_first < ptr_last ) ) {
165 switch( *ptr_first ) {
171 ptr_first = json_details::mem_skip_until_end_of_string<
172 ParseState::is_unchecked_input>( ParseState::exec_tag, ptr_first,
175 ErrorReason::UnexpectedEndOfData, parse_state );
178 if( DAW_UNLIKELY( ( prime_bracket_count == 1 ) &
179 ( second_bracket_count == 0 ) ) ) {
184 ++prime_bracket_count;
187 --prime_bracket_count;
188 if( prime_bracket_count == 0 ) {
191 ErrorReason::InvalidBracketing, parse_state );
192 result.last = ptr_first;
193 result.counter = cnt;
194 parse_state.first = ptr_first;
199 ++second_bracket_count;
202 --second_bracket_count;
208 ( second_bracket_count == 0 ),
209 ErrorReason::InvalidBracketing, parse_state );
212 result.last = ptr_first;
213 result.counter = cnt;
214 parse_state.first = ptr_first;
218 template<
char PrimLeft,
typename ParseState>
219 DAW_ATTRIB_NOINLINE
static constexpr ParseState
222 constexpr
char PrimRight = PrimLeft ==
'{' ?
'}' :
']';
223 constexpr
char SecLeft = PrimLeft ==
'{' ?
'[' :
'{';
224 constexpr
char SecRight = SecLeft ==
'{' ?
'}' :
']';
225 using CharT =
typename ParseState::CharT;
226 auto result = parse_state;
228 std::uint32_t prime_bracket_count = 1;
229 std::uint32_t second_bracket_count = 0;
230 CharT *ptr_first = parse_state.first;
232 if( *ptr_first == PrimLeft ) {
236 switch( *ptr_first ) {
242 ptr_first = json_details::mem_skip_until_end_of_string<
243 ParseState::is_unchecked_input>( ParseState::exec_tag, ptr_first,
247 if( DAW_UNLIKELY( ( prime_bracket_count == 1 ) &
248 ( second_bracket_count == 0 ) ) ) {
253 ++prime_bracket_count;
256 --prime_bracket_count;
257 if( prime_bracket_count == 0 ) {
261 result.last = ptr_first;
262 result.counter = cnt;
263 parse_state.first = ptr_first;
268 ++second_bracket_count;
271 --second_bracket_count;
#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.
#define daw_json_ensure(Bool,...)
Ensure that Bool is true. If false pass rest of args to daw_json_error.
std::bool_constant< is_zero_terminated_string_v< T > > is_zero_terminated_string
Customization point traits.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.