11 #include "../daw_json_exception.h"
14 #include <daw/daw_assume.h>
15 #include <daw/daw_attributes.h>
16 #include <daw/daw_check_exceptions.h>
17 #include <daw/daw_likely.h>
18 #include <daw/daw_string_view.h>
27 #include <string_view>
29 #ifdef DAW_USE_EXCEPTIONS
37 template<
bool ShouldThrow = use_daw_json_exceptions_v>
38 [[maybe_unused, noreturn]] DAW_ATTRIB_NOINLINE
void
40 #ifdef DAW_USE_EXCEPTIONS
41 if constexpr( ShouldThrow ) {
42 throw json_exception( reason );
48 #ifdef DAW_USE_EXCEPTIONS
53 template<
bool ShouldThrow = use_daw_json_exceptions_v,
typename ParseState>
54 [[maybe_unused, noreturn]] DAW_ATTRIB_NOINLINE
static void
56 #ifdef DAW_USE_EXCEPTIONS
57 if constexpr( ShouldThrow ) {
58 if( location.first ) {
59 throw json_exception( reason, location.first );
61 if( location.class_first ) {
62 throw json_exception( reason, location.class_first );
64 throw json_exception( reason );
71 #ifdef DAW_USE_EXCEPTIONS
76 template<
bool ShouldThrow = use_daw_json_exceptions_v>
77 [[maybe_unused, noreturn]] DAW_ATTRIB_NOINLINE
static void
79 #ifdef DAW_USE_EXCEPTIONS
80 if constexpr( ShouldThrow ) {
81 throw json_exception( reason );
87 #ifdef DAW_USE_EXCEPTIONS
92 template<
bool ShouldThrow = use_daw_json_exceptions_v>
93 [[maybe_unused, noreturn]] DAW_ATTRIB_NOINLINE
static void
95 #ifdef DAW_USE_EXCEPTIONS
96 if constexpr( ShouldThrow ) {
97 throw json_exception( reason );
103 #ifdef DAW_USE_EXCEPTIONS
108 template<
bool ShouldThrow = use_daw_json_exceptions_v,
typename ParseState>
109 [[maybe_unused, noreturn]] DAW_ATTRIB_NOINLINE
static void
111 ParseState
const &location ) {
112 #ifdef DAW_USE_EXCEPTIONS
113 if constexpr( ShouldThrow ) {
114 using namespace std::string_literals;
115 if( location.class_first and location.first ) {
116 static constexpr std::size_t max_len = 150;
117 std::size_t
const len = [&]( ) -> std::size_t {
118 if( location.first ==
nullptr or location.class_first ==
nullptr ) {
119 if( location.class_first ==
nullptr or
120 location.class_last ==
nullptr ) {
123 return std::min(
static_cast<std::size_t
>( std::distance(
124 location.class_first, location.class_last ) ),
127 return std::min(
static_cast<std::size_t
>( std::distance(
128 location.class_first, location.first + 1 ) ),
131 throw json_exception( reason,
132 std::string_view( location.class_first, len ) );
134 throw json_exception( reason );
142 #ifdef DAW_USE_EXCEPTIONS
147 template<
bool ShouldThrow = use_daw_json_exceptions_v,
typename ParseState>
148 [[maybe_unused, noreturn]] DAW_ATTRIB_NOINLINE
static void
150 ParseState
const &location ) {
151 #ifdef DAW_USE_EXCEPTIONS
152 if constexpr( ShouldThrow ) {
153 using namespace std::string_literals;
154 if( location.first ) {
155 throw json_exception( reason, location.first );
157 if( location.class_first ) {
158 throw json_exception( reason, location.class_first );
160 throw json_exception( reason );
167 #ifdef DAW_USE_EXCEPTIONS
178 #define daw_json_assert( Bool, ... ) \
180 if( DAW_UNLIKELY( not( Bool ) ) ) { \
181 daw_json_error( __VA_ARGS__ ); \
189 #define daw_json_assert_weak( Bool, ... ) \
191 if constexpr( not ParseState::is_unchecked_input ) { \
192 if( DAW_UNLIKELY( not( Bool ) ) ) { \
193 daw_json_error( __VA_ARGS__ ); \
constexpr bool use_daw_json_exceptions_v
Definition: daw_json_assert.h:32
DAW_ATTRIB_NOINLINE void daw_json_error(ErrorReason reason)
Definition: daw_json_assert.h:39
Definition: daw_from_json.h:22
#define DAW_JSON_VER
Definition: version.h:11