15#include <daw/daw_traits.h>
16#include <daw/daw_uint_buffer.h>
24 namespace json_details::string_quote {
25 template<std::
size_t N,
char c>
27 auto const lhs = b & ( 0xFF_u64 << ( N * 8U ) );
28 using rhs = daw::constant<to_uint64( static_cast<unsigned char>( c ) )
30 return to_uint8( not( lhs - rhs::value ) );
33 template<std::
size_t N,
char c>
34 DAW_ATTRIB_INLINE
inline constexpr UInt8
test_at_byte( UInt32 b ) {
35 auto const lhs = b & ( 0xFF_u32 << ( N * 8U ) );
36 using rhs = daw::constant<to_uint32( static_cast<unsigned char>( c ) )
38 return to_uint8( not( lhs - rhs::value ) );
41 template<
typename CharT>
43 bool keep_going = last - first >= 8;
45 auto buff = daw::to_uint64_buffer( first );
54 auto const s7 = test_at_byte<7U, '\\'>( buff );
55 auto const s6 = test_at_byte<6U, '\\'>( buff );
56 auto const s5 = test_at_byte<5U, '\\'>( buff );
57 auto const s4 = test_at_byte<4U, '\\'>( buff );
58 auto const s3 = test_at_byte<3U, '\\'>( buff );
59 auto const s2 = test_at_byte<2U, '\\'>( buff );
60 auto const s1 = test_at_byte<1U, '\\'>( buff );
61 auto const s0 = test_at_byte<0U, '\\'>( buff );
63 keep_going = not( q0 | q1 | q2 | q3 | q4 | q5 | q6 | q7 | s0 | s1 |
64 s2 | s3 | s4 | s5 | s6 | s7 );
65 keep_going = keep_going &
static_cast<bool>( last - first >= 16 );
66 first +=
static_cast<int>( keep_going ) * 8;
68 first -= *( first - 1 ) ==
'\\' ? 1 : 0;
71 template<
typename CharT>
73 bool keep_going = last - first >= 4;
76 auto buff = daw::to_uint32_buffer( first );
81 auto const s3 = test_at_byte<3U, '\\'>( buff );
82 auto const s2 = test_at_byte<2U, '\\'>( buff );
83 auto const s1 = test_at_byte<1U, '\\'>( buff );
84 auto const s0 = test_at_byte<0U, '\\'>( buff );
85 keep_going = not( q0 | q1 | q2 | q3 | s0 | s1 | s2 | s3 );
86 keep_going = keep_going &
static_cast<bool>( last - first >= 8 );
87 first +=
static_cast<int>( keep_going ) * 4;
89 first -= *( first - 1 ) ==
'\\' ? 1 : 0;
93 template<
typename ParseState>
95 -> std::enable_if_t<ParseState::is_unchecked_input, std::size_t> {
97 using CharT =
typename ParseState::CharT;
98 std::ptrdiff_t need_slow_path = -1;
104 if constexpr( traits::not_same_v<
typename ParseState::exec_tag_t,
106 first = mem_skip_until_end_of_string<true>(
107 ParseState::exec_tag, first, last, need_slow_path );
111 auto const sz = last - first;
114 }
else if( sz >= 4 ) {
118 while( *first !=
'"' ) {
119 while( [](
char c ) {
120 return ( c !=
'"' ) & ( c !=
'\\' );
124 if( *first ==
'\\' ) {
125 if( need_slow_path < 0 ) {
135 return static_cast<std::size_t
>( need_slow_path );
138 template<
typename ParseState>
140 -> std::enable_if_t<not ParseState::is_unchecked_input, std::size_t> {
142 using CharT =
typename ParseState::CharT;
143 std::ptrdiff_t need_slow_path = -1;
146 if constexpr( traits::not_same_v<
typename ParseState::exec_tag_t,
148 first = mem_skip_until_end_of_string<false>(
149 ParseState::exec_tag, first, last, need_slow_path );
151 if constexpr( not ParseState::exclude_special_escapes ) {
152 if( CharT *
const l =
parse_state.last; l - first >= 8 ) {
154 }
else if( last - first >= 4 ) {
158 if constexpr( ParseState::is_zero_terminated_string ) {
159 if constexpr( ParseState::exclude_special_escapes ) {
160 while( *first !=
'\0' ) {
167 if( need_slow_path < 0 ) {
186 }
else if( c ==
'"' ) {
192 while( ( *first != 0 ) & ( *first !=
'"' ) ) {
193 while( ( *first != 0 ) & ( *first !=
'"' ) &
194 ( *first !=
'\\' ) ) {
198 if( ( ( *first != 0 ) & ( *first ==
'\\' ) ) ) {
199 if( need_slow_path < 0 ) {
209 if constexpr( ParseState::exclude_special_escapes ) {
210 while( first < last ) {
217 if( need_slow_path < 0 ) {
236 }
else if( c ==
'"' ) {
242 while( first < last and *first !=
'"' ) {
243 while( first < last and
244 ( ( *first !=
'"' ) & ( *first !=
'\\' ) ) ) {
248 if( first < last and *first ==
'\\' ) {
249 if( need_slow_path < 0 ) {
260 if constexpr( ParseState::is_zero_terminated_string ) {
268 return static_cast<std::size_t
>( need_slow_path );
#define daw_json_assert_weak(Bool,...)
Definition: daw_json_assert.h:190
#define daw_json_assert(Bool,...)
Definition: daw_json_assert.h:179
ParseState & parse_state
Definition: daw_json_parse_class.h:182
constexpr void skip_to_first4(CharT *&first, CharT *const last)
Definition: daw_json_parse_string_quote.h:72
constexpr void skip_to_first8(CharT *&first, CharT *const last)
Definition: daw_json_parse_string_quote.h:42
constexpr UInt8 test_at_byte(UInt64 b)
Definition: daw_json_parse_string_quote.h:26
DAW_ATTRIB_NOINLINE void daw_json_error(ErrorReason reason)
Definition: daw_json_assert.h:39
Definition: daw_from_json.h:22
Definition: daw_json_exec_modes.h:19
Definition: daw_json_parse_string_quote.h:92
static constexpr auto parse_nq(ParseState &parse_state) -> std::enable_if_t< not ParseState::is_unchecked_input, std::size_t >
Definition: daw_json_parse_string_quote.h:139
static constexpr auto parse_nq(ParseState &parse_state) -> std::enable_if_t< ParseState::is_unchecked_input, std::size_t >
Definition: daw_json_parse_string_quote.h:94
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.
Definition: version.h:16