23 #include <daw/cpp_17.h>
24 #include <daw/daw_attributes.h>
25 #include <daw/daw_likely.h>
26 #include <daw/daw_traits.h>
31 #include <type_traits>
45 template<
json_options_t PolicyFlags = json_details::default_policy_flag,
46 typename Allocator = json_details::NoAllocator>
50 static constexpr
bool is_default_parse_policy =
51 PolicyFlags == json_details::default_policy_flag and
52 std::is_same_v<Allocator, json_details::NoAllocator>;
64 static constexpr
bool is_unchecked_input =
65 json_details::get_bits_for<options::CheckedParseMode>( PolicyFlags ) ==
66 options::CheckedParseMode::no;
73 std::size_t>( PolicyFlags ),
81 static constexpr
bool allow_escaped_names =
82 json_details::get_bits_for<options::AllowEscapedNames>( PolicyFlags ) ==
83 options::AllowEscapedNames::yes;
88 static constexpr
bool force_name_equal_check =
89 json_details::get_bits_for<options::ForceFullNameCheck>(
90 PolicyFlags ) == options::ForceFullNameCheck::yes;
96 json_details::get_bits_for<options::ZeroTerminatedString>(
97 PolicyFlags ) == options::ZeroTerminatedString::yes;
102 static constexpr
bool precise_ieee754 =
103 json_details::get_bits_for<options::IEEE754Precise>( PolicyFlags ) ==
104 options::IEEE754Precise::yes;
109 static constexpr
bool minified_document =
110 json_details::get_bits_for<options::MinifiedDocument>( PolicyFlags ) ==
111 options::MinifiedDocument::yes;
116 static constexpr
bool exclude_special_escapes =
117 json_details::get_bits_for<options::ExcludeSpecialEscapes>(
118 PolicyFlags ) == options::ExcludeSpecialEscapes::yes;
121 static constexpr
bool allow_leading_zero_plus =
true;
123 static constexpr
bool use_exact_mappings_by_default =
124 json_details::get_bits_for<options::UseExactMappingsByDefault>(
125 PolicyFlags ) == options::UseExactMappingsByDefault::yes;
127 static constexpr
bool must_verify_end_of_data_is_valid =
128 json_details::get_bits_for<options::MustVerifyEndOfDataIsValid>(
129 PolicyFlags ) == options::MustVerifyEndOfDataIsValid::yes;
131 static constexpr
bool expect_long_strings =
132 json_details::get_bits_for<options::ExpectLongNames>( PolicyFlags ) ==
133 options::ExpectLongNames::yes;
137 std::size_t>( PolicyFlags ),
145 std::size_t counter = 0;
147 template<
auto... PolicyOptions>
149 json_details::set_bits( PolicyFlags, PolicyOptions... ), Allocator>;
161 : json_details::AllocatorWrapper<Allocator>( alloc )
172 , class_last( cl ) {}
175 iterator cl, Allocator
const &alloc )
176 : json_details::AllocatorWrapper<Allocator>( alloc )
180 , class_last( cl ) {}
184 iterator cf = iterator{ }, iterator cl = iterator{ } )
const {
193 result.class_first = cf;
196 result.class_last = cl;
201 DAW_ATTRIB_INLINE constexpr decltype(
auto ) get_allocator( )
const {
202 return json_details::AllocatorWrapper<Allocator>::get_allocator( );
205 template<
typename Alloc>
208 template<
typename Alloc>
211 Alloc
const &alloc ) {
217 json_details::NoAllocator
const & ) {
221 template<
typename Alloc>
222 [[nodiscard]] constexpr
auto
224 if constexpr( std::is_same_v<Alloc, json_details::NoAllocator> ) {
227 auto result = with_allocator( first, last, class_first, class_last,
228 p.get_allocator( ) );
234 template<
typename Alloc>
235 [[nodiscard]] constexpr with_allocator_type<Alloc>
238 with_allocator( first, last, class_first, class_last, alloc );
239 result.counter = counter;
243 [[nodiscard]] DAW_ATTRIB_INLINE constexpr
auto
251 template<
typename Alloc>
254 return { f, l, f, l, alloc };
257 template<
typename Alloc>
260 json_details::NoAllocator
const & ) {
261 return { f, l, f, l };
264 [[nodiscard]] DAW_ATTRIB_INLINE constexpr
iterator data( )
const {
268 [[nodiscard]] DAW_ATTRIB_INLINE constexpr
iterator data_end( )
const {
272 [[nodiscard]] DAW_ATTRIB_INLINE constexpr
iterator begin( )
const {
276 [[nodiscard]] DAW_ATTRIB_INLINE constexpr
iterator end( )
const {
280 [[nodiscard]] DAW_ATTRIB_INLINE constexpr
bool empty( )
const {
285 return first >= last or *first ==
'\0';
287 return first >= last;
291 [[nodiscard]] DAW_ATTRIB_INLINE constexpr
bool has_more( )
const {
295 template<std::
size_t N>
296 constexpr
bool starts_with(
char const ( &rhs )[N] )
const {
297 static_assert( N > 0 );
298 if( size( ) < ( N - 1 ) ) {
302 for( std::size_t n = 0; n < ( N - 1 ); ++n ) {
303 result = result & ( first[n] == rhs[n] );
309 DAW_ATTRIB_INLINE constexpr
void move_to_next_of_unchecked( ) {
311 json_details::memchr_unchecked<c, exec_tag_t, expect_long_strings>(
316 DAW_ATTRIB_INLINE constexpr
void move_to_next_of_checked( ) {
318 json_details::memchr_checked<c, exec_tag_t, expect_long_strings>(
323 DAW_ATTRIB_INLINE constexpr
void move_to_next_of( ) {
324 if( is_unchecked_input ) {
325 move_to_next_of_unchecked<c>( );
327 move_to_next_of_checked<c>( );
331 [[nodiscard]] DAW_ATTRIB_INLINE constexpr
char front( )
const {
335 [[nodiscard]] DAW_ATTRIB_INLINE constexpr
char front_checked( )
const {
341 [[nodiscard]] DAW_ATTRIB_INLINE constexpr std::size_t size( )
const {
342 assert( last >= first );
343 return static_cast<std::size_t
>( last - first );
346 [[nodiscard]] constexpr
bool is_null( )
const {
347 return first ==
nullptr;
350 DAW_ATTRIB_INLINE constexpr
void remove_prefix( ) {
354 DAW_ATTRIB_INLINE constexpr
void remove_prefix( std::size_t n ) {
355 first +=
static_cast<std::ptrdiff_t
>( n );
358 constexpr
void set_class_position( ) {
369 class_first = new_pos.
f;
370 class_last = new_pos.
l;
374 return { class_first, class_last };
377 constexpr
void trim_left_checked( ) {
378 return CommentPolicy::trim_left_checked( *
this );
381 constexpr
void trim_left_unchecked( ) {
382 return CommentPolicy::trim_left_unchecked( *
this );
385 [[nodiscard]] constexpr
bool is_literal_end( )
const {
386 return CommentPolicy::is_literal_end( *first );
389 [[nodiscard]] DAW_ATTRIB_INLINE constexpr
bool
391 return (
static_cast<unsigned>(
static_cast<unsigned char>( *first ) ) -
395 [[nodiscard]] constexpr
bool is_opening_bracket_checked( )
const {
396 return DAW_LIKELY( first < last ) and *first ==
'[';
399 [[nodiscard]] constexpr
bool is_opening_brace_checked( )
const {
400 return DAW_LIKELY( first < last ) and *first ==
'{';
403 [[nodiscard]] constexpr
bool is_closing_brace_checked( )
const {
404 return DAW_LIKELY( first < last ) and *first ==
'}';
407 [[nodiscard]] constexpr
bool is_quotes_checked( )
const {
408 return DAW_LIKELY( first < last ) and *first ==
'"';
411 DAW_ATTRIB_INLINE constexpr
void trim_left( ) {
412 if constexpr( is_unchecked_input ) {
413 trim_left_unchecked( );
415 trim_left_checked( );
419 constexpr
void move_next_member_or_end_unchecked( ) {
420 trim_left_unchecked( );
421 if( *first ==
',' ) {
423 trim_left_unchecked( );
427 DAW_ATTRIB_FLATINLINE
inline constexpr
void
429 trim_left_checked( );
431 if( *first ==
',' ) {
436 if( DAW_LIKELY( first < last ) and *first ==
',' ) {
443 DAW_ATTRIB_INLINE constexpr
void move_next_member_or_end( ) {
444 if constexpr( is_unchecked_input ) {
445 move_next_member_or_end_unchecked( );
447 move_next_member_or_end_checked( );
451 DAW_ATTRIB_INLINE constexpr
void move_next_member( ) {
452 if constexpr( is_unchecked_input ) {
453 CommentPolicy::move_next_member_unchecked( *
this );
456 move_next_member_or_end_checked( );
460 constexpr
void move_to_next_class_member( ) {
461 CommentPolicy::template move_to_next_of<
'"',
'}'>( *this );
464 [[nodiscard]] constexpr
bool is_at_next_class_member( )
const {
465 return parse_policy_details::in<
'"',
'}'>( *first );
468 [[nodiscard]] constexpr
bool is_at_next_array_element( )
const {
469 return parse_policy_details::in<',', ']'>( *first );
472 [[nodiscard]] constexpr
bool is_at_token_after_value( )
const {
473 return parse_policy_details::in<',', '}', ']'>( *first );
476 template<
char PrimLeft>
479 return CommentPolicy::template skip_bracketed_item_checked<PrimLeft>(
483 template<
char PrimLeft>
486 return CommentPolicy::template skip_bracketed_item_unchecked<PrimLeft>(
491 if constexpr( is_unchecked_input ) {
492 return skip_bracketed_item_unchecked<
'{'>( );
494 return skip_bracketed_item_checked<
'{'>( );
499 if constexpr( is_unchecked_input ) {
500 return skip_bracketed_item_unchecked<'['>( );
502 return skip_bracketed_item_checked<'['>( );
511 template<
typename Allocator>
518 template<
typename Allocator>
525 json_details::NoAllocator> {
535 template<
json_options_t PolicyFlags = json_details::default_policy_flag,
536 typename Allocator = json_details::NoAllocator>
538 daw::conditional_t<(PolicyFlags == json_details::default_policy_flag and
539 std::is_same_v<Allocator, json_details::NoAllocator>),
542 template<
typename ParsePolicy>
544 daw::conditional_t<ParsePolicy::is_default_parse_policy,
552 template<
auto... PolicyFlags>
555 json_details::are_option_flags<decltype( PolicyFlags )...>,
556 "Only registered policy types are allowed" );
562 json_details::default_policy_flag;
566 template<
typename... Ts>
569 template<
auto... PolicyFlags>
572 template<
auto... PolicyFlags>
575 PolicyFlags... ) )::value ) {
576 static_assert(
sizeof...( PolicyFlags ) == 1 );
578 return ( PolicyFlags, ... );
588 template<
auto... PolicyFlags>
593 #define DAW_JSON_CONFORMANCE_FLAGS \
594 daw::json::options::AllowEscapedNames::yes, \
595 daw::json::options::MustVerifyEndOfDataIsValid::yes, \
596 daw::json::options::IEEE754Precise::yes, \
597 daw::json::options::ExcludeSpecialEscapes::yes
600 options::parse_flags<DAW_JSON_CONFORMANCE_FLAGS>;
#define daw_json_ensure(Bool,...)
Ensure that Bool is true. If false pass rest of args to daw_json_error.
std::uint32_t json_options_t
PolicyCommentTypes
Allow comments in JSON. The supported modes are none, C++ style comments, and # hash style comments....
ExecModeTypes
Allow for different optimizations. Currently only the compile_time path is fully supported....
std::true_type is_policy_flag(parse_flags_t< PolicyFlags... >)
DAW_CONSTEVAL auto make_parse_flags()
constexpr auto parse_flags
Specify parse policy flags in to_json calls. See cookbook item parse_options.md.
daw::conditional_t<(PolicyFlags==json_details::default_policy_flag and std::is_same_v< Allocator, json_details::NoAllocator >), DefaultParsePolicy, BasicParsePolicy< PolicyFlags, Allocator > > GetParsePolicy
BasicParsePolicy(char const *, char const *, char const *, char const *, Allocator const &) -> BasicParsePolicy< json_details::default_policy_flag, Allocator >
BasicParsePolicy() -> BasicParsePolicy<>
daw::conditional_t< ParsePolicy::is_default_parse_policy, DefaultParsePolicy, ParsePolicy > TryDefaultParsePolicy
constexpr auto ConformancePolicy
std::bool_constant< is_zero_terminated_string_v< T > > is_zero_terminated_string
Customization point traits.
Handles the bounds and policy items for parsing execution and comments.
constexpr DAW_ATTRIB_INLINE bool is_space_unchecked() const
constexpr DAW_ATTRIB_INLINE BasicParsePolicy skip_bracketed_item_unchecked()
static constexpr with_allocator_type< Alloc > with_allocator(iterator f, iterator l, Alloc const &alloc)
static constexpr BasicParsePolicy with_allocator(iterator f, iterator l, iterator cf, iterator cl, json_details::NoAllocator const &)
switch_t< json_details::get_bits_for< options::ExecModeTypes, std::size_t >(PolicyFlags), constexpr_exec_tag, runtime_exec_tag, simd_exec_tag > exec_tag_t
static constexpr with_allocator_type< Alloc > with_allocator(iterator f, iterator l, iterator cf, iterator cl, Alloc const &alloc)
constexpr auto with_allocator(BasicParsePolicy< PolicyFlags, Alloc > p) const
static constexpr BasicParsePolicy with_allocator(iterator f, iterator l, json_details::NoAllocator const &)
constexpr BasicParsePolicy copy(iterator f=iterator{ }, iterator l=iterator{ }, iterator cf=iterator{ }, iterator cl=iterator{ }) const
constexpr DAW_ATTRIB_INLINE auto with_allocator(json_details::NoAllocator const &) const
constexpr with_allocator_type< Alloc > with_allocator(Alloc const &alloc) const
BasicParsePolicy()=default
switch_t< json_details::get_bits_for< options::PolicyCommentTypes, std::size_t >(PolicyFlags), NoCommentSkippingPolicy, CppCommentSkippingPolicy, HashCommentSkippingPolicy > CommentPolicy
constexpr void move_next_member_or_end_checked()
static DAW_CONSTEVAL json_options_t policy_flags()
constexpr DAW_ATTRIB_INLINE BasicParsePolicy skip_bracketed_item_checked()
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.