16 #include <daw/daw_hide.h>
25 template<
typename Range>
26 DAW_ATTRIBUTE_FLATTEN
static constexpr
void
27 skip_comments_unchecked( Range &rng ) {
28 while( rng.front( ) ==
'/' ) {
29 switch( *( rng.first + 1 ) ) {
31 rng.template move_to_next_of_unchecked<'\n'>( );
35 rng.remove_prefix( 2 );
37 rng.template move_to_next_of_unchecked<'*'>( );
39 if( rng.front( ) ==
'/' ) {
52 template<
typename Range>
53 DAW_ATTRIBUTE_FLATTEN
static constexpr
void
54 skip_comments_checked( Range &rng ) {
55 while( rng.has_more( ) and rng.front( ) ==
'/' ) {
56 if( not rng.has_more( ) ) {
59 switch( *( rng.first + 1 ) ) {
61 rng.template move_to_next_of_checked<'\n'>( );
62 if( rng.has_more( ) ) {
67 rng.remove_prefix( 2 );
68 while( rng.has_more( ) ) {
69 rng.template move_to_next_of_checked<'*'>( );
70 if( rng.has_more( ) ) {
73 if( not rng.has_more( ) ) {
75 }
else if( rng.front( ) ==
'/' ) {
88 template<
typename Range>
89 DAW_ATTRIBUTE_FLATTEN
static constexpr
void skip_comments( Range &rng ) {
90 if constexpr( Range::is_unchecked_input ) {
91 skip_comments_unchecked( rng );
93 skip_comments_checked( rng );
98 template<
typename Range>
99 DAW_ATTRIBUTE_FLATTEN
static constexpr
void
101 skip_comments_checked( rng );
102 while( rng.has_more( ) and rng.is_space_unchecked( ) ) {
103 rng.remove_prefix( );
104 skip_comments_checked( rng );
108 template<
typename Range>
109 DAW_ATTRIBUTE_FLATTEN
static constexpr
void
111 skip_comments_unchecked( rng );
112 while( rng.is_space_unchecked( ) ) {
113 rng.remove_prefix( );
117 template<
char... keys,
typename Range>
119 skip_comments( rng );
122 while( not parse_policy_details::in<keys...>( rng.front( ) ) ) {
125 rng.remove_prefix( );
126 skip_comments( rng );
131 return c ==
'\0' or c ==
',' or c ==
']' or c ==
'}' or c ==
'#';
134 template<
char PrimLeft,
char PrimRight,
char SecLeft,
char SecRight,
136 DAW_ATTRIBUTE_FLATTEN
static constexpr Range
141 std::uint32_t prime_bracket_count = 1;
142 std::uint32_t second_bracket_count = 0;
143 char const *ptr_first = rng.first;
144 char const *
const ptr_last = rng.last;
148 if( *ptr_first == PrimLeft ) {
152 switch( *ptr_first ) {
158 if constexpr( not std::is_same_v<
typename Range::exec_tag_t,
160 ptr_first = json_details::mem_skip_until_end_of_string<
161 Range::is_unchecked_input>( Range::exec_tag, ptr_first,
164 while( ptr_first < ptr_last and *ptr_first !=
'"' ) {
165 if( *ptr_first ==
'\\' ) {
167 if( ptr_first >= ptr_last ) {
175 ErrorReason::UnexpectedEndOfData, rng );
178 if( prime_bracket_count == 1 and second_bracket_count == 0 ) {
183 ++prime_bracket_count;
186 --prime_bracket_count;
187 if( prime_bracket_count == 0 ) {
189 ErrorReason::InvalidBracketing, rng );
193 result.last = ptr_first;
194 result.counter = cnt;
195 rng.first = ptr_first;
200 ++second_bracket_count;
203 --second_bracket_count;
208 ErrorReason::UnexpectedEndOfData, rng );
209 switch( *ptr_first ) {
212 while( ( ptr_last - ptr_first ) > 1 and *ptr_first !=
'\n' ) {
218 while( ( ptr_last - ptr_first ) >= 3 and *ptr_first !=
'*' and
219 *std::next( ptr_first ) !=
'/' ) {
231 ( second_bracket_count == 0 ),
232 ErrorReason::InvalidBracketing, rng );
235 result.last = ptr_first;
236 result.counter = cnt;
237 rng.first = ptr_first;
241 template<
char PrimLeft,
char PrimRight,
char SecLeft,
char SecRight,
243 DAW_ATTRIBUTE_FLATTEN
static constexpr Range
248 std::uint32_t prime_bracket_count = 1;
249 std::uint32_t second_bracket_count = 0;
250 char const *ptr_first = rng.first;
251 if( *ptr_first == PrimLeft ) {
255 switch( *ptr_first ) {
261 if constexpr( not std::is_same_v<
typename Range::exec_tag_t,
263 ptr_first = json_details::mem_skip_until_end_of_string<
264 Range::is_unchecked_input>( Range::exec_tag, ptr_first,
267 while( *ptr_first !=
'"' ) {
268 if( *ptr_first ==
'\\' ) {
276 if( prime_bracket_count == 1 and second_bracket_count == 0 ) {
281 ++prime_bracket_count;
284 --prime_bracket_count;
285 if( prime_bracket_count == 0 ) {
289 result.last = ptr_first;
290 result.counter = cnt;
291 rng.first = ptr_first;
296 ++second_bracket_count;
299 --second_bracket_count;
303 switch( *ptr_first ) {
306 while( *ptr_first !=
'\n' ) {
312 while( *ptr_first !=
'*' and *std::next( ptr_first ) !=
'/' ) {