14 #include <restinio/impl/string_caseless_compare.hpp> 16 #include <restinio/helpers/easy_parser.hpp> 18 #include <restinio/expected.hpp> 58 constexpr auto get()
const noexcept {
return m_value; }
71 if( m_value > maximum )
72 throw exception_t(
"invalid value for " 73 "http_field_parser::rfc::qvalue_t" );
76 auto get()
const noexcept {
return m_value; }
163 underlying_char_array_t result;
164 if( qvalue_details::maximum == m_value )
166 std::strcpy( &result[0],
"1.000" );
173 result[2] =
'0' +
static_cast<
char>(m_value / 100u);
174 const auto d2 = m_value % 100u;
175 result[3] =
'0' +
static_cast<
char>(d2 / 10u);
176 const auto d3 = d2 % 10u;
177 result[4] =
'0' +
static_cast<
char>(d3);
204 constexpr auto as_uint()
const noexcept {
return m_value; }
208 return std::string{ &make_char_array().front() };
214 return (to << &what.make_char_array().front());
262 inline constexpr bool 265 return (
ch >=
'\x41' &&
ch <=
'\x5A') ||
266 (
ch >=
'\x61' &&
ch <=
'\x7A');
318 inline constexpr bool 321 return (
ch >=
'\x21' &&
ch <=
'\x7E');
354 inline constexpr bool 357 constexpr unsigned short left = 0x80u;
358 constexpr unsigned short right = 0xFFu;
360 const unsigned short t =
static_cast<
unsigned short>(
361 static_cast<
unsigned char>(
ch));
377 inline constexpr bool 383 (
ch >=
'\x23' &&
ch <=
'\x5B') ||
384 (
ch >=
'\x5D' &&
ch <=
'\x7E') ||
399 inline constexpr bool 404 (
ch >=
'\x21' &&
ch <=
'\x27') ||
405 (
ch >=
'\x2A' &&
ch <=
'\x5B') ||
406 (
ch >=
'\x5D' &&
ch <=
'\x7E') ||
439 static constexpr bool 559 static constexpr bool 612 else if(
'\\' ==
ch.
m_ch )
1185 dest.m_value += m_multiplier *
1186 static_cast< qvalue_t::underlying_uint_t >(digit -
'0');
1315 typename Element_Producer >
1320 "Element_Producer should be a value producer type" );
1328 Element_Producer && element )
1379 typename Element_Producer >
1384 "Element_Producer should be a value producer type" );
1392 Element_Producer && element )
1460 "Element_Producer should be a value producer type" );
1506 "Element_Producer should be a value producer type" );
non_empty_comma_separated_list_producer_t(Element_Producer &&element)
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
RESTINIO_NODISCARD constexpr bool is_ctext(const char ch) noexcept
Is a character a ctext?
const qvalue_t::underlying_uint_t m_multiplier
A helper wrapper to indicate that value hasn't been checked yet and should be checked in the construc...
constexpr underlying_uint_t zero
The minimal allowed value for a qvalue.
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const
params_with_opt_value_producer_t()=default
constexpr qvalue_t()=default
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const noexcept
constexpr underlying_uint_t maximum
The maximal allowed value for a qvalue.
auto get() const noexcept
params_with_value_producer_t()=default
Element_Producer m_element
qvalue_t::underlying_uint_t m_value
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
A class for holding the parsed value of qvalue from RFC7231.
RESTINIO_NODISCARD auto make_parser()
Helper function that creates an instance of producer of parameter_with_optional_value_container.
Element_Producer m_element
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
constexpr auto get() const noexcept
actual_producer_t m_producer
underlying_uint_t m_value
constexpr trusted(underlying_uint_t value) noexcept
constexpr qvalue_t(trusted val) noexcept
actual_producer_t m_producer
untrusted(underlying_uint_t value)
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from)
underlying_uint_t m_value
static constexpr qvalue_details::extremum_max_t maximum
The indicator that tells that new qvalue object should have the maximal allowed value.
constexpr qvalue_t(qvalue_details::extremum_min_t) noexcept
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
const underlying_uint_t m_value
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
constexpr digit_consumer_t(qvalue_t::underlying_uint_t m)
A helper class to be used to accumulate actual integer while when the next digit is extracted from th...
qvalue_t(untrusted val) noexcept
constexpr qvalue_t(qvalue_details::extremum_max_t) noexcept
friend std::ostream & operator<<(std::ostream &to, const qvalue_t &what)
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from)
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const
maybe_empty_comma_separated_list_producer_t(Element_Producer &&element)
underlying_char_array_t make_char_array() const noexcept
An empty type to be used as indicator of negative search result.
RESTINIO_NODISCARD auto try_parse(source_t &from)
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const
RESTINIO_NODISCARD auto try_parse_field(const generic_request_t< Extra_Data > &req, http_field_t field_id, string_view_t default_value=string_view_t{})
A helper function for extraction and parsing a value of HTTP-field.
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const noexcept
void consume(zero_initialized_unit_t &dest, char &&digit)
static constexpr qvalue_details::extremum_min_t zero
The indicator that tells that new qvalue object should have the minimal allowed value.
constexpr auto as_uint() const noexcept
RESTINIO_NODISCARD auto make_parser()
Helper function that creates an instance of producer of parameter_with_mandatory_value_container.
A helper wrapper to indicate that value is already checked and shouldn't be checked again...
RESTINIO_NODISCARD auto try_parse(source_t &from)
std::enable_if< std::is_same< Parameter_Container, query_string_params_t >::value||std::is_same< Parameter_Container, router::route_params_t >::value, optional_t< Value_Type > >::type opt_value(const Parameter_Container ¶ms, string_view_t key)
Gets the value of a parameter specified by key wrapped in optional_t<Value_Type> if parameter exists ...