23#include <daw/cpp_17.h>
24#include <daw/daw_attributes.h>
25#include <daw/daw_likely.h>
26#include <daw/daw_not_null.h>
27#include <daw/daw_rw_ref.h>
28#include <daw/daw_traits.h>
47 template<
json_options_t PolicyFlags = json_details::default_policy_flag,
48 typename Allocator = json_details::NoAllocator>
52 static constexpr bool is_default_parse_policy =
53 PolicyFlags == json_details::default_policy_flag and
54 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 precise_ieee754 =
104 json_details::get_bits_for<options::IEEE754Precise>( PolicyFlags ) ==
105 options::IEEE754Precise::yes;
110 static constexpr bool minified_document =
111 json_details::get_bits_for<options::MinifiedDocument>( PolicyFlags ) ==
112 options::MinifiedDocument::yes;
117 static constexpr bool exclude_special_escapes =
118 json_details::get_bits_for<options::ExcludeSpecialEscapes>(
119 PolicyFlags ) == options::ExcludeSpecialEscapes::yes;
122 static constexpr bool allow_leading_zero_plus =
true;
124 static constexpr bool use_exact_mappings_by_default =
125 json_details::get_bits_for<options::UseExactMappingsByDefault>(
126 PolicyFlags ) == options::UseExactMappingsByDefault::yes;
128 static constexpr bool must_verify_end_of_data_is_valid =
129 json_details::get_bits_for<options::MustVerifyEndOfDataIsValid>(
130 PolicyFlags ) == options::MustVerifyEndOfDataIsValid::yes;
132 static constexpr bool expect_long_strings =
133 json_details::get_bits_for<options::ExpectLongNames>( PolicyFlags ) ==
134 options::ExpectLongNames::yes;
137 switch_t<json_details::get_bits_for<options::PolicyCommentTypes,
138 std::size_t>( PolicyFlags ),
146 std::size_t counter = 0;
148 template<
auto... PolicyOptions>
150 json_details::set_bits( PolicyFlags, PolicyOptions... ), Allocator>;
162 : json_details::AllocatorWrapper<Allocator>( alloc )
173 , class_last( cl ) {}
181 , counter( cnter ) {}
184 iterator cl, Allocator
const &alloc )
185 : json_details::AllocatorWrapper<Allocator>( alloc )
189 , class_last( cl ) {}
193 iterator cf = iterator{ }, iterator cl = iterator{ } )
const {
194 BasicParsePolicy result = *
this;
202 result.class_first = cf;
205 result.class_last = cl;
211 return json_details::AllocatorWrapper<Allocator>::get_allocator( );
214 template<
typename Alloc>
217 template<
typename Alloc>
220 Alloc
const &alloc ) {
226 json_details::NoAllocator
const & ) {
230 template<
typename Alloc>
231 [[nodiscard]]
constexpr auto
233 if constexpr( std::is_same_v<Alloc, json_details::NoAllocator> ) {
236 auto result = with_allocator(
243 template<
typename Alloc>
244 [[nodiscard]]
constexpr with_allocator_type<Alloc>
247 with_allocator( first, last, class_first, class_last, alloc );
248 result.counter = counter;
252 [[nodiscard]] DAW_ATTRIB_INLINE
constexpr auto
260 template<
typename Alloc>
266 template<
typename Alloc>
269 json_details::NoAllocator
const & ) {
289 [[nodiscard]] DAW_ATTRIB_INLINE
constexpr bool empty( )
const {
294 return first >= last or *first ==
'\0';
296 return first >= last;
300 [[nodiscard]] DAW_ATTRIB_INLINE
constexpr bool has_more( )
const {
301#if not defined( NDEBUG )
303 ErrorReason::InvalidNull );
308 template<std::
size_t N>
309 DAW_ATTRIB_NONNULL( )
310 constexpr
bool starts_with(
char const ( &rhs )[N] )
const {
311 static_assert( N > 0 );
312 if( size( ) < ( N - 1 ) ) {
316 for( std::size_t n = 0; n < ( N - 1 ); ++n ) {
317 result = result & ( first[n] == rhs[n] );
322 template<std::
size_t N>
324 if( not starts_with( rhs ) ) {
327 first +=
static_cast<std::ptrdiff_t
>( N - 1 );
334 json_details::memchr_unchecked<c, exec_tag_t, expect_long_strings>(
335 daw::not_null{ daw::never_null, first },
336 daw::not_null{ daw::never_null, last } );
342 json_details::memchr_checked<c, exec_tag_t, expect_long_strings>(
343 daw::not_null{ first }, daw::not_null{ last } );
348 if( is_unchecked_input ) {
349 move_to_next_of_unchecked<c>( );
351 move_to_next_of_checked<c>( );
355 [[nodiscard]] DAW_ATTRIB_INLINE
constexpr char front( )
const {
361 first < last, ErrorReason::UnexpectedEndOfData, *
this );
365 [[nodiscard]] DAW_ATTRIB_INLINE
constexpr std::size_t
size( )
const {
366 assert( last >= first );
367 return static_cast<std::size_t
>( last - first );
370 [[nodiscard]]
constexpr bool is_null( )
const {
371 return first ==
nullptr;
379 first +=
static_cast<std::ptrdiff_t
>( n );
393 class_first = new_pos.
f;
394 class_last = new_pos.
l;
398 return { class_first, class_last };
402 return CommentPolicy::trim_left_checked( *
this );
406 return CommentPolicy::trim_left_unchecked( *
this );
410 return CommentPolicy::is_literal_end( *first );
413 [[nodiscard]] DAW_ATTRIB_INLINE
constexpr bool
415 return (
static_cast<unsigned>(
static_cast<unsigned char>( *first ) ) -
420 return DAW_LIKELY( first < last ) and *first ==
'[';
424 return DAW_LIKELY( first < last ) and *first ==
'{';
428 return DAW_LIKELY( first < last ) and *first ==
'}';
432 return DAW_LIKELY( first < last ) and *first ==
'"';
436 if constexpr( is_unchecked_input ) {
437 trim_left_unchecked( );
439 trim_left_checked( );
444 trim_left_unchecked( );
445 if( *first ==
',' ) {
447 trim_left_unchecked( );
452 trim_left_checked( );
454 if( *first ==
',' ) {
459 if( DAW_LIKELY( first < last ) and *first ==
',' ) {
467 if constexpr( is_unchecked_input ) {
468 move_next_member_or_end_unchecked( );
470 move_next_member_or_end_checked( );
475 if constexpr( is_unchecked_input ) {
476 CommentPolicy::move_next_member_unchecked( *
this );
479 move_next_member_or_end_checked( );
484 CommentPolicy::template move_to_next_of<
'"',
'}'>( *this );
488 return parse_policy_details::in<
'"',
'}'>( *first );
492 return parse_policy_details::in<',', ']'>( *first );
496 return parse_policy_details::in<',', '}', ']'>( *first );
499 template<
char PrimLeft>
502 return CommentPolicy::template skip_bracketed_item_checked<PrimLeft>(
506 template<
char PrimLeft>
509 return CommentPolicy::template skip_bracketed_item_unchecked<PrimLeft>(
514 if constexpr( is_unchecked_input ) {
515 return skip_bracketed_item_unchecked<
'{'>( );
517 return skip_bracketed_item_checked<
'{'>( );
522 if constexpr( is_unchecked_input ) {
523 return skip_bracketed_item_unchecked<'['>( );
525 return skip_bracketed_item_checked<'['>( );
534 template<
typename Allocator>
541 template<
typename Allocator>
548 json_details::NoAllocator> {
550 using BasicParsePolicy::BasicParsePolicy;
558 template<
json_options_t PolicyFlags = json_details::default_policy_flag,
559 typename Allocator = json_details::NoAllocator>
561 daw::conditional_t<(PolicyFlags == json_details::default_policy_flag and
562 std::is_same_v<Allocator, json_details::NoAllocator>),
565 template<
typename ParsePolicy>
567 daw::conditional_t<ParsePolicy::is_default_parse_policy,
575 template<
auto... PolicyFlags>
578 json_details::are_option_flags<
decltype( PolicyFlags )...>,
579 "Only registered policy types are allowed" );
585 json_details::default_policy_flag;
589 template<
typename... Ts>
592 template<
auto... PolicyFlags>
595 template<
auto... PolicyFlags>
597 if constexpr(
decltype( details::is_policy_flag(
598 PolicyFlags... ) )::value ) {
599 static_assert(
sizeof...( PolicyFlags ) == 1 );
601 return ( PolicyFlags, ... );
611 template<
auto... PolicyFlags>
613 details::make_parse_flags<PolicyFlags...>( );
616#define DAW_JSON_CONFORMANCE_FLAGS \
617 daw::json::options::AllowEscapedNames::yes, \
618 daw::json::options::MustVerifyEndOfDataIsValid::yes, \
619 daw::json::options::IEEE754Precise::yes, \
620 daw::json::options::ExcludeSpecialEscapes::yes
623 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
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()
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.