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FF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
27 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
28 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
29 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
30 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
31 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
39 static constexpr std::size_t
48 static constexpr char r[] =
"128";
55 static constexpr char r[] =
"127";
61 static constexpr char r[] =
"int8_t";
70 static constexpr std::size_t
79 static constexpr char r[] =
"0";
86 static constexpr char r[] =
"255";
92 static constexpr char r[] =
"uint8_t";
101 static constexpr std::size_t
110 static constexpr char r[] =
"32768";
117 static constexpr char r[] =
"32767";
123 static constexpr char r[] =
"int16_t";
132 static constexpr std::size_t
141 static constexpr char r[] =
"0";
148 static constexpr char r[] =
"65535";
154 static constexpr char r[] =
"uint16_t";
163 static constexpr std::size_t
172 static constexpr char r[] =
"2147483648";
179 static constexpr char r[] =
"2147483647";
185 static constexpr char r[] =
"int32_t";
194 static constexpr std::size_t
203 static constexpr char r[] =
"0";
210 static constexpr char r[] =
"4294967295";
216 static constexpr char r[] =
"uint32_t";
225 static constexpr std::size_t
234 static constexpr char r[] =
"9223372036854775808";
241 static constexpr char r[] =
"9223372036854775807";
247 static constexpr char r[] =
"int64_t";
256 static constexpr std::size_t
265 static constexpr char r[] =
"0";
272 static constexpr char r[] =
"18446744073709551615";
278 static constexpr char r[] =
"uint64_t";
283template <
typename Integer >
286 const std::uint8_t *
const mapping_table,
287 const char * data_begin,
288 const char * data_end,
289 bool apply_minus_sign,
294 if( apply_minus_sign )
295 while( data_begin != data_end )
297 result = result*10 - mapping_table[
static_cast< std::size_t
>( *data_begin++ ) ];
300 while( data_begin != data_end )
302 result = result*10 + mapping_table[
static_cast< std::size_t
>( *data_begin++ ) ];
308template <
typename Integer >
311 const std::uint8_t *
const mapping_table,
312 const char * data_begin,
313 const char * data_end,
319 while( data_begin != data_end )
321 result = result * 10 + mapping_table[
static_cast< std::size_t
>( *data_begin++ ) ];
327template <
typename Traits >
328typename Traits::type_t
331 bool apply_minus_sign =
false;
332 if(
'-' == *data_begin )
334 if( !std::is_signed< typename Traits::type_t >::value )
338 "invalid {} value: unsigned starts with minus",
339 Traits::type_name() ) };
343 apply_minus_sign =
true;
346 else if(
'+' == *data_begin )
351 const auto representation_size =
static_cast< std::size_t
>( data_end - data_begin );
353 if( 0 == representation_size )
354 throw exception_t{ fmt::format(
"invalid {} value: empty string", Traits::type_name() ) };
356 if( Traits::digits_representation_max_size() < representation_size )
359 "invalid {} value: max digits for type is {}",
361 Traits::digits_representation_max_size() ) };
363 const std::uint8_t *
const mapping_table = digits_mapping< std::uint8_t >();
368 [&](
auto d ){
return 0xFF == mapping_table[
static_cast< std::size_t
>( d ) ]; } ) )
371 fmt::format(
"invalid {} value: invalid digit", Traits::type_name() ) };
374 if( Traits::digits_representation_max_size() == representation_size )
376 const char *
const posssible_max = apply_minus_sign ?
377 Traits::min_representation() : Traits::max_representation();
379 if( 0 < std::memcmp( data_begin, posssible_max, representation_size ) )
380 throw std::out_of_range{
381 fmt::format(
"invalid {} value: out of range", Traits::type_name() ) };
384 using is_signed_t =
typename std::is_signed< typename Traits::type_t >::type;
387 parse_integer_no_checks< typename Traits::type_t >(
Exception class for all exceptions thrown by RESTinio.
bool_constant< false > false_type
bool_constant< true > true_type
Integer parse_integer_no_checks(const std::uint8_t *const mapping_table, const char *data_begin, const char *data_end, bool apply_minus_sign, std::true_type)
Traits::type_t parse_integer(const char *data_begin, const char *data_end)
const C * digits_mapping()
RESTINIO_NODISCARD bool any_of(Tuple &&tuple, Predicate &&predicate)
static const char * min_representation()
static const char * type_name()
static const char * max_representation()
static constexpr std::size_t digits_representation_max_size()
static const char * max_representation()
static const char * type_name()
static constexpr std::size_t digits_representation_max_size()
static const char * min_representation()
static const char * type_name()
static const char * min_representation()
static constexpr std::size_t digits_representation_max_size()
static const char * max_representation()
static const char * max_representation()
static const char * type_name()
static const char * min_representation()
static constexpr std::size_t digits_representation_max_size()
static constexpr std::size_t digits_representation_max_size()
static const char * min_representation()
static const char * type_name()
static const char * max_representation()
static const char * min_representation()
static constexpr std::size_t digits_representation_max_size()
static const char * max_representation()
static const char * type_name()
static constexpr std::size_t digits_representation_max_size()
static const char * type_name()
static const char * min_representation()
static const char * max_representation()
static constexpr std::size_t digits_representation_max_size()
static const char * min_representation()
static const char * type_name()
static const char * max_representation()