15#include <daw/daw_attributes.h>
16#include <daw/daw_likely.h>
17#include <daw/daw_not_null.h>
20#include <daw/stdinc/move_fwd_exch.h>
25#if defined( DAW_JSON_SHOW_ERROR_BEFORE_TERMINATE )
30#if defined( DAW_USE_EXCEPTIONS )
38#if defined( DAW_USE_EXCEPTIONS )
39 [[noreturn, maybe_unused]] DAW_ATTRIB_NOINLINE
inline void
40 default_error_handler_throwing( json_exception &&jex,
void * ) {
41 throw std::move( jex );
45 [[noreturn, maybe_unused]] DAW_ATTRIB_NOINLINE
inline void
47#if defined( DAW_JSON_SHOW_ERROR_BEFORE_TERMINATE )
48 std::cerr <<
"Error: " << jex.reason( ) <<
'\n';
56 daw::not_null<void ( * )( json_exception &&,
void * )>;
58#if defined( DAW_USE_EXCEPTIONS )
60 default_error_handler_throwing;
67 namespace json_details {
68 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
69 handle_error( json_exception &&jex ) {
76 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
78 json_details::handle_error( json_exception( reason ) );
81 template<
typename ParseState>
82 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
84 if( location.first ) {
85 json_details::handle_error( json_exception( reason, location.first ) );
87 if( location.class_first ) {
88 json_details::handle_error(
89 json_exception( reason, location.class_first ) );
91 json_details::handle_error( json_exception( reason ) );
94 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
96 json_details::handle_error( json_exception( reason ) );
99 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
101 json_details::handle_error( json_exception( reason ) );
104 template<
typename ParseState>
105 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
107 ParseState
const &location ) {
108 if( location.class_first and location.first ) {
109 static constexpr std::size_t max_len = 150;
110 std::size_t
const len = [&]( ) -> std::size_t {
111 if( location.first ==
nullptr or location.class_first ==
nullptr ) {
112 if( location.class_first ==
nullptr or
113 location.class_last ==
nullptr ) {
116 auto const dist =
static_cast<std::size_t
>( location.class_last -
117 location.class_first );
118 if( dist < max_len ) {
123 auto const dist =
static_cast<std::size_t
>( location.class_first -
124 location.first + 1 );
125 if( dist < max_len ) {
130 json_details::handle_error( json_exception(
131 reason, std::string_view( location.class_first, len ) ) );
133 json_details::handle_error( json_exception( reason ) );
136 template<
typename ParseState>
137 [[noreturn]] DAW_ATTRIB_NOINLINE
inline void
139 ParseState
const &location ) {
140 if( location.first ) {
141 json_details::handle_error( json_exception( reason, location.first ) );
143 if( location.class_first ) {
144 json_details::handle_error(
145 json_exception( reason, location.class_first ) );
147 json_details::handle_error( json_exception( reason ) );
154#define daw_json_ensure( Bool, ... ) \
156 if( DAW_UNLIKELY( not( Bool ) ) ) { \
157 daw_json_error( __VA_ARGS__ ); \
163#define daw_json_assert_weak( Bool, ... ) \
165 if constexpr( not ParseState::is_unchecked_input ) { \
166 if( DAW_UNLIKELY( not( Bool ) ) ) { \
167 daw_json_error( __VA_ARGS__ ); \
DAW_ATTRIB_NOINLINE void daw_json_error(ErrorReason reason)
Customization point traits.
daw::not_null< void(*)(json_exception &&, void *)> daw_json_error_handler_t
constexpr bool use_daw_json_exceptions_v
DAW_ATTRIB_NOINLINE void default_error_handler_terminating(json_exception &&jex, void *)
static thread_local daw_json_error_handler_t daw_json_error_handler
static thread_local void * daw_json_error_handler_data
#define DAW_JSON_VER
The version string used in namespace definitions. Must be a valid namespace name.