25 namespace json_details {
26 template<
char c,
typename ExecTag>
27 DAW_ATTRIB_FLATINLINE
static constexpr daw::not_null<char const *>
28 memchr_unchecked_long( daw::not_null<char const *> first,
29 daw::not_null<char const *> last ) {
30#if not defined( NDEBUG )
33#if DAW_HAS_BUILTIN( __builtin_char_memchr )
34 return __builtin_char_memchr(
35 first,
'"',
static_cast<std::size_t
>( last - first ) );
37 if( not json_details::use_constexpr_exec_mode<ExecTag>( ) ) {
38 return static_cast<char const *
>(
39 std::memchr(
static_cast<void const *
>( first ),
41 static_cast<std::size_t
>( last - first ) ) );
44 while( *first != c ) {
52 DAW_ATTRIB_FLATINLINE
static constexpr daw::not_null<char const *>
53 memchr_unchecked_short( daw::not_null<char const *> first ) {
54 while( *first != c ) {
68 template<
char c,
typename ExecTag,
bool expect_
long>
69 DAW_ATTRIB_FLATINLINE
static constexpr daw::not_null<char const *>
70 memchr_unchecked( daw::not_null<char const *> first,
71 daw::not_null<char const *> last ) {
72#if not defined( NDEBUG )
75 if constexpr( expect_long ) {
76 return memchr_unchecked_long<c, ExecTag>( first, last );
78 return memchr_unchecked_short<c>( first );
82 template<
char c,
typename ExecTag>
83 DAW_ATTRIB_FLATINLINE
static constexpr daw::not_null<char const *>
84 memchr_checked_long( daw::not_null<char const *> first,
85 daw::not_null<char const *> last ) {
86#if not defined( NDEBUG )
89#if DAW_HAS_BUILTIN( __builtin_char_memchr )
90 return __builtin_char_memchr(
91 first,
'"',
static_cast<std::size_t
>( last - first ) );
92#elif DAW_HAS_BUILTIN( __builtin_memchr )
93 return static_cast<char const *
>( __builtin_memchr(
94 first,
'"',
static_cast<std::size_t
>( last - first ) ) );
96 if( not json_details::use_constexpr_exec_mode<ExecTag>( ) ) {
97 return static_cast<char const *
>(
98 std::memchr(
static_cast<void const *
>( first ),
100 static_cast<std::size_t
>( last - first ) ) );
102 while( DAW_LIKELY( first < last ) and *first != c ) {
110 DAW_ATTRIB_INLINE
static constexpr daw::not_null<char const *>
111 memchr_checked_short( daw::not_null<char const *> first,
112 daw::not_null<char const *>
const last ) {
113#if not defined( NDEBUG )
116 while( DAW_LIKELY( first < last ) and *first != c ) {
130 template<
char c,
typename ExecTag,
bool expect_
long>
131 DAW_ATTRIB_FLATINLINE
static constexpr daw::not_null<char const *>
132 memchr_checked( daw::not_null<char const *> first,
133 daw::not_null<char const *> last ) {
134 if constexpr( expect_long ) {
135 return memchr_checked_long<c, ExecTag>( first, last );
137 return memchr_checked_short<c>( first, last );
141 template<
typename ExecTag,
char... chars>
142 DAW_ATTRIB_FLATINLINE
constexpr daw::not_null<char const *>
143 mempbrk_unchecked_long( daw::not_null<char const *> first ) {
144#if DAW_HAS_BUILTIN( __builtin_strpbrk )
145 constexpr char const needles[]{ chars...,
'\0' };
146 daw::not_null<char const *> res = __builtin_strpbrk( first, needles );
149 if( not json_details::use_constexpr_exec_mode<ExecTag>( ) ) {
150 constexpr char const needles[]{ chars...,
'\0' };
151 char const *res = std::strpbrk( first, needles );
152#if not defined( NDEBUG )
157 while( not parse_policy_details::in<chars...>( *first ) ) {
164 template<
char... chars>
165 DAW_ATTRIB_INLINE
constexpr daw::not_null<char const *>
166 mempbrk_unchecked_short( daw::not_null<char const *> first ) {
167 while( not parse_policy_details::in<chars...>( *first ) ) {
173 template<
typename ExecTag,
bool expect_long,
char... chars>
174 DAW_ATTRIB_FLATINLINE
constexpr daw::not_null<char const *>
175 mempbrk_unchecked( daw::not_null<char const *> first ) {
176 if constexpr( expect_long ) {
177 return mempbrk_unchecked_long<ExecTag, chars...>( first );
179 return mempbrk_unchecked_short<chars...>( first );
183 template<
typename ExecTag,
char... chars>
184 DAW_ATTRIB_FLATINLINE
constexpr daw::not_null<char const *>
185 mempbrk_checked_long( daw::not_null<char const *> first,
186 daw::not_null<char const *> last ) {
187#if not defined( NDEBUG )
190 if( not json_details::use_constexpr_exec_mode<ExecTag>( ) ) {
191 return mem_move_to_next_of<
false, chars...>(
192 ExecTag{ }, first, last );
194 while( DAW_LIKELY( first < last ) and
195 not parse_policy_details::in<chars...>( *first ) ) {
201 template<
char... chars>
202 DAW_ATTRIB_FLATINLINE
constexpr daw::not_null<char const *>
203 mempbrk_checked_short( daw::not_null<char const *> first,
204 daw::not_null<char const *> last ) {
205#if not defined( NDEBUG )
208 while( DAW_LIKELY( first < last ) and
209 not parse_policy_details::in<chars...>( *first ) ) {
215 template<
typename ExecTag,
bool expect_long,
char... chars>
216 DAW_ATTRIB_FLATINLINE
constexpr daw::not_null<char const *>
217 mempbrk_checked( daw::not_null<char const *> first,
218 daw::not_null<char const *> last ) {
219 if constexpr( expect_long ) {
220 return mempbrk_checked_long<ExecTag, chars...>( first, last );
222 return mempbrk_checked_short<chars...>( first, last );
226 template<
bool is_unchecked_input,
typename ExecTag,
bool expect_long,
228 DAW_ATTRIB_FLATINLINE
constexpr daw::not_null<char const *>
229 mempbrk( daw::not_null<char const *> first,
230 daw::not_null<char const *> last ) {
232 if constexpr( is_unchecked_input ) {
233 return mempbrk_unchecked<ExecTag, expect_long, chars...>( first );
235 return mempbrk_checked<ExecTag, expect_long, chars...>( first, last );