18 #include <daw/daw_attributes.h>
19 #include <daw/daw_likely.h>
20 #include <daw/daw_traits.h>
28 template<
typename ParseState>
29 DAW_ATTRIB_FLATINLINE
static constexpr
void
31 while( parse_state.front( ) ==
'/' ) {
32 switch( *( parse_state.first + 1 ) ) {
34 parse_state.template move_to_next_of_unchecked<'\n'>( );
35 parse_state.remove_prefix( );
38 parse_state.remove_prefix( 2 );
40 parse_state.template move_to_next_of_unchecked<'*'>( );
41 parse_state.remove_prefix( );
42 if( parse_state.front( ) ==
'/' ) {
43 parse_state.remove_prefix( );
46 parse_state.remove_prefix( );
55 template<
typename ParseState>
56 DAW_ATTRIB_FLATINLINE
static constexpr
void
58 while( parse_state.has_more( ) and parse_state.front( ) ==
'/' ) {
59 if( not parse_state.has_more( ) ) {
62 switch( *( parse_state.first + 1 ) ) {
64 parse_state.template move_to_next_of_checked<'\n'>( );
65 if( parse_state.has_more( ) ) {
66 parse_state.remove_prefix( );
70 parse_state.remove_prefix( 2 );
71 while( parse_state.has_more( ) ) {
72 parse_state.template move_to_next_of_checked<'*'>( );
73 if( parse_state.has_more( ) ) {
74 parse_state.remove_prefix( );
76 if( not parse_state.has_more( ) ) {
78 }
else if( parse_state.front( ) ==
'/' ) {
79 parse_state.remove_prefix( );
82 parse_state.remove_prefix( );
91 template<
typename ParseState>
92 DAW_ATTRIB_FLATINLINE
static constexpr
void
94 if constexpr( ParseState::is_unchecked_input ) {
95 skip_comments_unchecked( parse_state );
97 skip_comments_checked( parse_state );
102 template<
typename ParseState>
103 DAW_ATTRIB_FLATINLINE
static constexpr
void
105 skip_comments_checked( parse_state );
106 while( parse_state.has_more( ) and parse_state.is_space_unchecked( ) ) {
107 parse_state.remove_prefix( );
108 skip_comments_checked( parse_state );
112 template<
typename ParseState>
113 DAW_ATTRIB_FLATINLINE
static constexpr
void
115 skip_comments_unchecked( parse_state );
116 while( parse_state.is_space_unchecked( ) ) {
117 parse_state.remove_prefix( );
121 template<
typename ParseState>
122 DAW_ATTRIB_FLATINLINE
static constexpr
void
124 parse_state.move_next_member_or_end_unchecked( );
127 template<
char... keys,
typename ParseState>
128 DAW_ATTRIB_FLATINLINE
static constexpr
void
130 skip_comments( parse_state );
132 ErrorReason::UnexpectedEndOfData, parse_state );
133 while( not parse_policy_details::in<keys...>( parse_state.front( ) ) ) {
135 ErrorReason::UnexpectedEndOfData, parse_state );
136 parse_state.remove_prefix( );
137 skip_comments( parse_state );
141 DAW_ATTRIB_FLATINLINE
static constexpr
bool is_literal_end(
char c ) {
142 return c ==
'\0' or c ==
',' or c ==
']' or c ==
'}' or c ==
'#';
145 template<
char PrimLeft,
typename ParseState>
146 DAW_ATTRIB_FLATINLINE
static constexpr ParseState
148 constexpr
char PrimRight = PrimLeft ==
'{' ?
'}' :
']';
149 constexpr
char SecLeft = PrimLeft ==
'{' ?
'[' :
'{';
150 constexpr
char SecRight = SecLeft ==
'{' ?
'}' :
']';
151 using CharT =
typename ParseState::CharT;
153 auto result = parse_state;
155 std::uint32_t prime_bracket_count = 1;
156 std::uint32_t second_bracket_count = 0;
157 CharT *ptr_first = parse_state.first;
158 CharT *
const ptr_last = parse_state.last;
159 if( DAW_UNLIKELY( ptr_first >= ptr_last ) ) {
162 if( *ptr_first == PrimLeft ) {
165 while( DAW_LIKELY( ptr_first < ptr_last ) ) {
166 switch( *ptr_first ) {
172 ptr_first = json_details::mem_skip_until_end_of_string<
173 ParseState::is_unchecked_input>( ParseState::exec_tag, ptr_first,
176 ErrorReason::UnexpectedEndOfData, parse_state );
179 if( prime_bracket_count == 1 and second_bracket_count == 0 ) {
184 ++prime_bracket_count;
187 --prime_bracket_count;
188 if( prime_bracket_count == 0 ) {
190 ErrorReason::InvalidBracketing, parse_state );
194 result.last = ptr_first;
195 result.counter = cnt;
196 parse_state.first = ptr_first;
201 ++second_bracket_count;
204 --second_bracket_count;
209 ErrorReason::UnexpectedEndOfData, parse_state );
210 switch( *ptr_first ) {
213 while( ( ptr_last - ptr_first ) > 1 and *ptr_first !=
'\n' ) {
219 while( ( ptr_last - ptr_first ) >= 3 and *ptr_first !=
'*' and
220 *std::next( ptr_first ) !=
'/' ) {
232 ( second_bracket_count == 0 ),
233 ErrorReason::InvalidBracketing, parse_state );
236 result.last = ptr_first;
237 result.counter = cnt;
238 parse_state.first = ptr_first;
242 template<
char PrimLeft,
typename ParseState>
243 DAW_ATTRIB_FLATINLINE
static constexpr ParseState
245 constexpr
char PrimRight = PrimLeft ==
'{' ?
'}' :
']';
246 constexpr
char SecLeft = PrimLeft ==
'{' ?
'[' :
'{';
247 constexpr
char SecRight = SecLeft ==
'{' ?
'}' :
']';
249 using CharT =
typename ParseState::CharT;
250 auto result = parse_state;
252 std::uint32_t prime_bracket_count = 1;
253 std::uint32_t second_bracket_count = 0;
254 CharT *ptr_first = parse_state.first;
255 if( *ptr_first == PrimLeft ) {
259 switch( *ptr_first ) {
265 ptr_first = json_details::mem_skip_until_end_of_string<
266 ParseState::is_unchecked_input>( ParseState::exec_tag, ptr_first,
270 if( prime_bracket_count == 1 and second_bracket_count == 0 ) {
275 ++prime_bracket_count;
278 --prime_bracket_count;
279 if( prime_bracket_count == 0 ) {
283 result.last = ptr_first;
284 result.counter = cnt;
285 parse_state.first = ptr_first;
290 ++second_bracket_count;
293 --second_bracket_count;
297 switch( *ptr_first ) {
300 while( *ptr_first !=
'\n' ) {
306 while( *ptr_first !=
'*' and *std::next( ptr_first ) !=
'/' ) {
#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.
Customization point traits.
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.