16 #include <daw/daw_hide.h>
21 #include <type_traits>
25 template<
typename Range>
26 DAW_ATTRIBUTE_FLATTEN
static constexpr
void
27 skip_comments_unchecked( Range &rng ) {
28 while( rng.front( ) ==
'#' ) {
30 rng.template move_to_next_of_unchecked<'\n'>( );
35 template<
typename Range>
36 DAW_ATTRIBUTE_FLATTEN
static constexpr
void
37 skip_comments_checked( Range &rng ) {
38 while( rng.has_more( ) and rng.front( ) ==
'#' ) {
40 rng.template move_to_next_of_checked<'\n'>( );
41 if( rng.front( ) ==
'\n' ) {
47 template<
typename Range>
48 DAW_ATTRIBUTE_FLATTEN
static constexpr
void skip_comments( Range &rng ) {
49 if constexpr( Range::is_unchecked_input ) {
50 skip_comments_unchecked( rng );
52 skip_comments_checked( rng );
57 template<
typename Range>
58 DAW_ATTRIBUTE_FLATTEN
static constexpr
void
60 skip_comments_checked( rng );
61 while( rng.has_more( ) and rng.is_space_unchecked( ) ) {
63 skip_comments_checked( rng );
67 template<
typename Range>
68 DAW_ATTRIBUTE_FLATTEN
static constexpr
void
70 skip_comments_unchecked( rng );
71 while( rng.is_space_unchecked( ) ) {
76 template<
char... keys,
typename Range>
82 while( not parse_policy_details::in<keys...>( rng.front( ) ) ) {
91 return c ==
'\0' or c ==
',' or c ==
']' or c ==
'}' or c ==
'#';
94 template<
char PrimLeft,
char PrimRight,
char SecLeft,
char SecRight,
96 DAW_ATTRIBUTE_FLATTEN
static constexpr Range
101 std::uint32_t prime_bracket_count = 1;
102 std::uint32_t second_bracket_count = 0;
103 char const *ptr_first = rng.first;
104 char const *
const ptr_last = rng.last;
108 if( *ptr_first == PrimLeft ) {
113 switch( *ptr_first ) {
119 if constexpr( not std::is_same_v<
typename Range::exec_tag_t,
121 ptr_first = json_details::mem_skip_until_end_of_string<
122 Range::is_unchecked_input>( Range::exec_tag, ptr_first,
126 *ptr_first !=
'"' ) {
127 if( *ptr_first ==
'\\' ) {
129 if( ptr_first >= ptr_last ) {
137 ErrorReason::UnexpectedEndOfData, rng );
140 if( prime_bracket_count == 1 and second_bracket_count == 0 ) {
145 ++prime_bracket_count;
148 --prime_bracket_count;
149 if( prime_bracket_count == 0 ) {
151 ErrorReason::InvalidBracketing, rng );
155 result.last = ptr_first;
156 result.counter = cnt;
157 rng.first = ptr_first;
162 ++second_bracket_count;
165 --second_bracket_count;
169 while( ptr_first < ptr_last and *ptr_first !=
'\n' ) {
172 if( ptr_first < ptr_last ) {
180 ( second_bracket_count == 0 ),
181 ErrorReason::InvalidBracketing, rng );
184 result.last = ptr_first;
185 result.counter = cnt;
186 rng.first = ptr_first;
190 template<
char PrimLeft,
char PrimRight,
char SecLeft,
char SecRight,
192 DAW_ATTRIBUTE_FLATTEN
static constexpr Range
197 std::uint32_t prime_bracket_count = 1;
198 std::uint32_t second_bracket_count = 0;
199 char const *ptr_first = rng.first;
200 if( *ptr_first == PrimLeft ) {
204 switch( *ptr_first ) {
210 if constexpr( not std::is_same_v<
typename Range::exec_tag_t,
212 ptr_first = json_details::mem_skip_until_end_of_string<
213 Range::is_unchecked_input>( Range::exec_tag, ptr_first,
216 while( *ptr_first !=
'"' ) {
217 if( *ptr_first ==
'\\' ) {
225 if( prime_bracket_count == 1 and second_bracket_count == 0 ) {
230 ++prime_bracket_count;
233 --prime_bracket_count;
234 if( prime_bracket_count == 0 ) {
238 result.last = ptr_first;
239 result.counter = cnt;
240 rng.first = ptr_first;
245 ++second_bracket_count;
248 --second_bracket_count;
252 while( *ptr_first !=
'\n' ) {