24#include <daw/cpp_17.h>
25#include <daw/daw_attributes.h>
26#include <daw/daw_consteval.h>
27#include <daw/daw_likely.h>
28#include <daw/daw_not_null.h>
29#include <daw/daw_rw_ref.h>
30#include <daw/daw_traits.h>
49 template<
json_options_t PolicyFlags = json_details::default_policy_flag,
50 typename Allocator = json_details::NoAllocator>
54 static constexpr bool is_default_parse_policy =
55 PolicyFlags == json_details::default_policy_flag and
56 std::is_same_v<Allocator, json_details::NoAllocator>;
65 static constexpr bool is_unchecked_input =
66 json_details::get_bits_for<options::CheckedParseMode>( PolicyFlags ) ==
67 options::CheckedParseMode::no;
73 json_details::get_bits_for<options::ExecModeTypes, std::size_t>(
82 static constexpr bool allow_escaped_names =
83 json_details::get_bits_for<options::AllowEscapedNames>( PolicyFlags ) ==
84 options::AllowEscapedNames::yes;
89 static constexpr bool force_name_equal_check =
90 json_details::get_bits_for<options::ForceFullNameCheck>(
91 PolicyFlags ) == options::ForceFullNameCheck::yes;
97 json_details::get_bits_for<options::ZeroTerminatedString>(
98 PolicyFlags ) == options::ZeroTerminatedString::yes;
103 static constexpr bool allow_string_mutation =
104 json_details::get_bits_for<options::AllowStringMutation>(
105 PolicyFlags ) == options::AllowStringMutation::yes;
110 static constexpr bool precise_ieee754 =
111 json_details::get_bits_for<options::IEEE754Precise>( PolicyFlags ) ==
112 options::IEEE754Precise::yes;
117 static constexpr bool minified_document =
118 json_details::get_bits_for<options::MinifiedDocument>( PolicyFlags ) ==
119 options::MinifiedDocument::yes;
124 static constexpr bool exclude_special_escapes =
125 json_details::get_bits_for<options::ExcludeSpecialEscapes>(
126 PolicyFlags ) == options::ExcludeSpecialEscapes::yes;
129 static constexpr bool allow_leading_zero_plus =
true;
131 static constexpr bool use_exact_mappings_by_default =
132 json_details::get_bits_for<options::UseExactMappingsByDefault>(
133 PolicyFlags ) == options::UseExactMappingsByDefault::yes;
135 static constexpr bool must_verify_end_of_data_is_valid =
136 json_details::get_bits_for<options::MustVerifyEndOfDataIsValid>(
137 PolicyFlags ) == options::MustVerifyEndOfDataIsValid::yes;
139 static constexpr bool expect_long_strings =
140 json_details::get_bits_for<options::ExpectLongNames>( PolicyFlags ) ==
141 options::ExpectLongNames::yes;
144 switch_t<json_details::get_bits_for<options::PolicyCommentTypes,
145 std::size_t>( PolicyFlags ),
149 using iterator = std::conditional_t<allow_string_mutation ,
150 char *,
char const *>;
155 std::size_t counter = 0;
157 template<
auto... PolicyOptions>
159 json_details::set_bits( PolicyFlags, PolicyOptions... ), Allocator>;
171 : json_details::AllocatorWrapper<Allocator>( alloc )
182 , class_last( cl ) {}
190 , counter( cnter ) {}
193 iterator cl, Allocator
const &alloc )
194 : json_details::AllocatorWrapper<Allocator>( alloc )
198 , class_last( cl ) {}
202 iterator cf = iterator{ }, iterator cl = iterator{ } )
const {
203 BasicParsePolicy result = *
this;
211 result.class_first = cf;
214 result.class_last = cl;
220 return json_details::AllocatorWrapper<Allocator>::get_allocator( );
223 template<
typename Alloc>
226 template<
typename Alloc>
229 Alloc
const &alloc ) {
235 json_details::NoAllocator
const & ) {
239 template<
typename Alloc>
240 [[nodiscard]]
constexpr auto
242 if constexpr( std::is_same_v<Alloc, json_details::NoAllocator> ) {
245 auto result = with_allocator(
252 template<
typename Alloc>
253 [[nodiscard]]
constexpr with_allocator_type<Alloc>
256 with_allocator( first, last, class_first, class_last, alloc );
257 result.counter = counter;
261 [[nodiscard]] DAW_ATTRIB_INLINE
constexpr auto
269 template<
typename Alloc>
275 template<
typename Alloc>
278 json_details::NoAllocator
const & ) {
298 [[nodiscard]] DAW_ATTRIB_INLINE
constexpr bool empty( )
const {
303 return first >= last or *first ==
'\0';
305 return first >= last;
309 [[nodiscard]] DAW_ATTRIB_INLINE
constexpr bool has_more( )
const {
310#if not defined( NDEBUG )
312 ErrorReason::InvalidNull );
317 template<std::
size_t N>
319 static_assert( N > 0 );
320 if( size( ) < ( N - 1 ) ) {
324 for( std::size_t n = 0; n < ( N - 1 ); ++n ) {
325 result = result & ( first[n] == rhs[n] );
330 template<std::
size_t N>
332 if( not starts_with( rhs ) ) {
335 first +=
static_cast<std::ptrdiff_t
>( N - 1 );
341 auto const position =
342 json_details::memchr_unchecked<c, exec_tag_t, expect_long_strings>(
343 daw::not_null<char const *>{ daw::never_null, first },
344 daw::not_null<char const *>{ daw::never_null, last } );
345 first = json_details::input_pointer( first, position.get( ) );
350 auto const position =
351 json_details::memchr_checked<c, exec_tag_t, expect_long_strings>(
352 daw::not_null<char const *>{ first },
353 daw::not_null<char const *>{ last } );
354 first = json_details::input_pointer( first, position.get( ) );
359 if( is_unchecked_input ) {
360 move_to_next_of_unchecked<c>( );
362 move_to_next_of_checked<c>( );
366 [[nodiscard]] DAW_ATTRIB_INLINE
constexpr char front( )
const {
372 first < last, ErrorReason::UnexpectedEndOfData, *
this );
376 [[nodiscard]] DAW_ATTRIB_INLINE
constexpr std::size_t
size( )
const {
377 assert( last >= first );
378 return static_cast<std::size_t
>( last - first );
381 [[nodiscard]]
constexpr bool is_null( )
const {
382 return first ==
nullptr;
390 first +=
static_cast<std::ptrdiff_t
>( n );
404 class_first = new_pos.
f;
405 class_last = new_pos.
l;
409 return { class_first, class_last };
413 return CommentPolicy::trim_left_checked( *
this );
417 return CommentPolicy::trim_left_unchecked( *
this );
421 return CommentPolicy::is_literal_end( *first );
424 [[nodiscard]] DAW_ATTRIB_INLINE
constexpr bool
426 return (
static_cast<unsigned>(
static_cast<unsigned char>( *first ) ) -
431 return DAW_LIKELY( first < last ) and *first ==
'[';
435 return DAW_LIKELY( first < last ) and *first ==
'{';
439 return DAW_LIKELY( first < last ) and *first ==
'}';
443 return DAW_LIKELY( first < last ) and *first ==
'"';
447 if constexpr( is_unchecked_input ) {
448 trim_left_unchecked( );
450 trim_left_checked( );
455 trim_left_unchecked( );
456 if( *first ==
',' ) {
458 trim_left_unchecked( );
463 trim_left_checked( );
465 if( *first ==
',' ) {
470 if( DAW_LIKELY( first < last ) and *first ==
',' ) {
478 if constexpr( is_unchecked_input ) {
479 move_next_member_or_end_unchecked( );
481 move_next_member_or_end_checked( );
486 if constexpr( is_unchecked_input ) {
487 CommentPolicy::move_next_member_unchecked( *
this );
490 move_next_member_or_end_checked( );
495 CommentPolicy::template move_to_next_of<
'"',
'}'>( *this );
499 return parse_policy_details::in<
'"',
'}'>( *first );
503 return parse_policy_details::in<',', ']'>( *first );
507 return parse_policy_details::in<',', '}', ']'>( *first );
510 template<json_details::SkipBracketedType BracketedType>
513 return CommentPolicy::template skip_bracketed_item_checked<
514 BracketedType>( *this );
517 template<json_details::SkipBracketedType BracketedType>
520 return CommentPolicy::template skip_bracketed_item_unchecked<
521 BracketedType>( *this );
525#if defined( DAW_JSON_HAS_STD_SIMD )
526 if constexpr( std::is_same_v<CommentPolicy, NoCommentSkippingPolicy> ) {
527 return json_details::skip_bracketed_item_simd<
528 json_details::SkipBracketedType::Class>( *this );
530#elif defined( DAW_JSON_HAS_SIMD )
531 if constexpr( std::is_same_v<CommentPolicy, NoCommentSkippingPolicy> ) {
532 if( not DAW_IS_CONSTANT_EVALUATED( ) ) {
533 return json_details::skip_bracketed_item_simd<
534 json_details::SkipBracketedType::Class>( *this );
538 if constexpr( is_unchecked_input ) {
539 return skip_bracketed_item_unchecked<
540 json_details::SkipBracketedType::Class>( );
542 return skip_bracketed_item_checked<
543 json_details::SkipBracketedType::Class>( );
548#if defined( DAW_JSON_HAS_STD_SIMD )
549 if constexpr( std::is_same_v<CommentPolicy, NoCommentSkippingPolicy> ) {
550 return json_details::skip_bracketed_item_simd<
551 json_details::SkipBracketedType::Array>( *this );
553#elif defined( DAW_JSON_HAS_SIMD )
554 if constexpr( std::is_same_v<CommentPolicy, NoCommentSkippingPolicy> ) {
555 if( not DAW_IS_CONSTANT_EVALUATED( ) ) {
556 return json_details::skip_bracketed_item_simd<
557 json_details::SkipBracketedType::Array>( *this );
561 if constexpr( is_unchecked_input ) {
562 return skip_bracketed_item_unchecked<
563 json_details::SkipBracketedType::Array>( );
565 return skip_bracketed_item_checked<
566 json_details::SkipBracketedType::Array>( );
576 template<
typename Allocator>
579 template<
typename Allocator>
587 template<
typename Allocator>
591 template<
typename Allocator>
597 json_details::NoAllocator> {
599 using BasicParsePolicy::BasicParsePolicy;
607 template<
json_options_t PolicyFlags = json_details::default_policy_flag,
608 typename Allocator = json_details::NoAllocator>
610 daw::conditional_t<(PolicyFlags == json_details::default_policy_flag and
611 std::is_same_v<Allocator, json_details::NoAllocator>),
614 template<
typename ParsePolicy>
616 daw::conditional_t<ParsePolicy::is_default_parse_policy,
624 template<
auto... PolicyFlags>
627 json_details::are_option_flags<
decltype( PolicyFlags )...>,
628 "Only registered policy types are allowed" );
634 json_details::default_policy_flag;
638 template<
typename... Ts>
641 template<
auto... PolicyFlags>
644 template<
auto... PolicyFlags>
646 if constexpr(
decltype( details::is_policy_flag(
647 PolicyFlags... ) )::value ) {
648 static_assert(
sizeof...( PolicyFlags ) == 1 );
650 return ( PolicyFlags, ... );
660 template<
auto... PolicyFlags>
662 details::make_parse_flags<PolicyFlags...>( );
665#define DAW_JSON_CONFORMANCE_FLAGS \
666 daw::json::options::AllowEscapedNames::yes, \
667 daw::json::options::MustVerifyEndOfDataIsValid::yes, \
668 daw::json::options::IEEE754Precise::yes, \
669 daw::json::options::ExcludeSpecialEscapes::yes
672 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
DAW_CONSTEVAL auto make_parse_flags()
std::false_type is_policy_flag(Ts...)
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
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.
DAW_ATTRIB_INLINE constexpr iterator data_end() const
constexpr BasicParsePolicy(iterator f, iterator l)
constexpr bool is_null() const
constexpr bool is_opening_bracket_checked() const
static constexpr BasicParsePolicy with_allocator(iterator f, iterator l, iterator cf, iterator cl, json_details::NoAllocator const &)
DAW_ATTRIB_INLINE constexpr BasicParsePolicy skip_bracketed_item_checked()
DAW_ATTRIB_INLINE constexpr BasicParsePolicy skip_array()
constexpr bool is_literal_end() const
DAW_ATTRIB_INLINE constexpr BasicParsePolicy skip_bracketed_item_unchecked()
DAW_ATTRIB_INLINE constexpr bool has_more() const
constexpr bool is_opening_brace_checked() const
DAW_ATTRIB_INLINE constexpr iterator begin() const
DAW_ATTRIB_INLINE constexpr std::size_t size() const
constexpr BasicParsePolicy(iterator f, iterator l, iterator cf, iterator cl, Allocator const &alloc)
DAW_ATTRIB_INLINE constexpr void remove_prefix(std::size_t n)
DAW_ATTRIB_INLINE constexpr iterator data() const
constexpr void set_class_position(class_pos_t new_pos)
constexpr class_pos_t get_class_position() const
constexpr BasicParsePolicy(iterator f, iterator l, iterator cf, iterator cl)
DAW_ATTRIB_INLINE constexpr void move_next_member()
DAW_ATTRIB_INLINE constexpr auto with_allocator(json_details::NoAllocator const &) const
DAW_ATTRIB_INLINE constexpr bool empty() const
constexpr bool starts_with_skip(char const (&rhs)[N])
constexpr bool is_at_next_array_element() const
constexpr auto with_allocator(BasicParsePolicy< PolicyFlags, Alloc > p) const
constexpr void trim_left_checked()
constexpr bool is_at_next_class_member() const
static constexpr BasicParsePolicy with_allocator(iterator f, iterator l, json_details::NoAllocator const &)
DAW_ATTRIB_INLINE constexpr void move_to_next_of()
switch_t< json_details::get_bits_for< options::ExecModeTypes, std::size_t >(PolicyFlags), default_exec_tag, constexpr_exec_tag, runtime_exec_tag, simd_exec_tag > exec_tag_t
constexpr BasicParsePolicy copy(iterator f=iterator{ }, iterator l=iterator{ }, iterator cf=iterator{ }, iterator cl=iterator{ }) const
DAW_ATTRIB_INLINE constexpr void remove_prefix()
constexpr BasicParsePolicy(iterator f, iterator l, iterator cf, iterator cl, std::size_t cnter)
constexpr void move_to_next_class_member()
constexpr void trim_left_unchecked()
constexpr void set_class_position()
DAW_ATTRIB_INLINE constexpr void move_to_next_of_unchecked()
DAW_ATTRIB_INLINE constexpr iterator end() const
DAW_ATTRIB_INLINE constexpr decltype(auto) get_allocator() const
DAW_ATTRIB_INLINE constexpr void move_next_member_or_end()
constexpr BasicParsePolicy(iterator f, iterator l, Allocator &alloc)
constexpr bool is_at_token_after_value() const
static constexpr with_allocator_type< Alloc > with_allocator(iterator f, iterator l, Alloc const &alloc)
static constexpr with_allocator_type< Alloc > with_allocator(iterator f, iterator l, iterator cf, iterator cl, Alloc const &alloc)
DAW_ATTRIB_INLINE constexpr bool is_space_unchecked() const
DAW_ATTRIB_INLINE constexpr char front() const
constexpr bool starts_with(char const (&rhs)[N]) const
BasicParsePolicy()=default
switch_t< json_details::get_bits_for< options::PolicyCommentTypes, std::size_t >(PolicyFlags), NoCommentSkippingPolicy, CppCommentSkippingPolicy, HashCommentSkippingPolicy > CommentPolicy
constexpr bool is_quotes_checked() const
constexpr void move_next_member_or_end_checked()
DAW_ATTRIB_INLINE constexpr BasicParsePolicy skip_class()
DAW_ATTRIB_INLINE constexpr void trim_left()
constexpr with_allocator_type< Alloc > with_allocator(Alloc const &alloc) const
static DAW_CONSTEVAL json_options_t policy_flags()
constexpr void move_next_member_or_end_unchecked()
std::conditional_t< allow_string_mutation, char *, char const * > iterator
DAW_ATTRIB_INLINE constexpr char front_checked() const
DAW_ATTRIB_INLINE constexpr void move_to_next_of_checked()
constexpr bool is_closing_brace_checked() const
constexpr DefaultParsePolicy(BasicParsePolicy &&other) noexcept
constexpr DefaultParsePolicy(BasicParsePolicy const &other) noexcept
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.