25namespace http_field_parsers
32namespace qvalue_details
73 "http_field_parser::rfc::qvalue_t" );
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);
211 friend std::ostream &
222 return a.as_uint() == b.as_uint();
229 return a.as_uint() != b.as_uint();
236 return a.as_uint() < b.as_uint();
243 return a.as_uint() <= b.as_uint();
265 return (ch >=
'\x41' && ch <=
'\x5A') ||
266 (ch >=
'\x61' && ch <=
'\x7A');
321 return (ch >=
'\x21' && ch <=
'\x7E');
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));
363 return (t >= left && t <= right);
383 (ch >=
'\x23' && ch <=
'\x5B') ||
384 (ch >=
'\x5D' && ch <=
'\x7E') ||
404 (ch >=
'\x21' && ch <=
'\x27') ||
405 (ch >=
'\x2A' && ch <=
'\x5B') ||
406 (ch >=
'\x5D' && ch <=
'\x7E') ||
439 static constexpr bool
489 std::size_t extracted_spaces{};
491 for( ch = from.getch();
502 if( extracted_spaces > 0u )
532 const auto ch = from.
getch();
535 reason = error_reason_t::unexpected_eof;
542 reason = error_reason_t::unexpected_character;
546 accumulator += ch.m_ch;
550 if( accumulator.empty() )
559 static constexpr bool
575 return make_unexpected( *try_result );
600 bool second_quote_extracted{
false };
603 const auto ch = from.
getch();
606 reason = error_reason_t::unexpected_eof;
611 second_quote_extracted =
true;
612 else if(
'\\' == ch.m_ch )
614 const auto next = from.
getch();
617 reason = error_reason_t::unexpected_eof;
620 else if(
SP == next.m_ch ||
HTAB == next.m_ch ||
624 accumulator += next.
m_ch;
628 reason = error_reason_t::unexpected_character;
634 accumulator += ch.m_ch;
637 reason = error_reason_t::unexpected_character;
642 while( !second_quote_extracted );
644 if( !second_quote_extracted )
657 const auto ch = from.
getch();
670 return make_unexpected( *try_result );
676 error_reason_t::unexpected_character
683 error_reason_t::unexpected_eof
712 const auto ch = from.
getch();
715 if(
'\\' == ch.m_ch )
717 const auto next = from.
getch();
720 if(
SP == next.m_ch ||
HTAB == next.m_ch ||
728 reason = error_reason_t::unexpected_character;
732 reason = error_reason_t::unexpected_character;
1075 return produce< bool >(
1114 return produce< bool >(
1129 return produce< std::string >(
1137 []( std::string & dest, std::string && what ) {
1142 ).try_parse( from );
1195 const auto parse_result = produce< zero_initialized_unit_t >(
1225 return make_unexpected( parse_result.error() );
1279 return produce< qvalue_t >(
1315 typename Element_Producer >
1319 static_assert( impl::is_producer_v<Element_Producer>,
1320 "Element_Producer should be a value producer type" );
1328 Element_Producer && element )
1336 Container tmp_value;
1340 const auto process_result =
sequence(
1347 ).try_process( from, tmp_value );
1349 if( !process_result )
1352 return make_unexpected( *process_result );
1379 typename Element_Producer >
1383 static_assert( impl::is_producer_v<Element_Producer>,
1384 "Element_Producer should be a value producer type" );
1392 Element_Producer && element )
1400 Container tmp_value;
1404 const auto process_result =
maybe(
1410 ).try_process( from, tmp_value );
1412 if( !process_result )
1415 return make_unexpected( *process_result );
1454 typename Element_Producer >
1459 static_assert( impl::is_producer_v<Element_Producer>,
1460 "Element_Producer should be a value producer type" );
1464 Element_Producer >{
std::move(element) };
1500 typename Element_Producer >
1505 static_assert( impl::is_producer_v<Element_Producer>,
1506 "Element_Producer should be a value producer type" );
1510 Element_Producer >{
std::move(element) };
1532 std::vector< parameter_with_mandatory_value_t >;
1572 const auto it = std::find_if( where.begin(), where.end(),
1573 [&what](
const auto & pair ) {
1574 return restinio::impl::is_equal_caseless( pair.first, what );
1576 if( it != where.end() )
1585namespace params_with_value_producer_details
1601 return produce< parameter_with_mandatory_value_container_t >(
1603 produce< parameter_with_mandatory_value_t >(
1608 >> ¶meter_with_mandatory_value_t::first,
1612 >> ¶meter_with_mandatory_value_t::second,
1614 >> ¶meter_with_mandatory_value_t::second
1633 :
public producer_tag< parameter_with_mandatory_value_container_t >
1684inline impl::params_with_value_producer_t
1696 std::pair< std::string, restinio::optional_t<std::string> >;
1707 std::vector< parameter_with_optional_value_t >;
1742 const auto it = std::find_if( where.begin(), where.end(),
1743 [&what](
const auto & pair ) {
1744 return restinio::impl::is_equal_caseless( pair.first, what );
1746 if( it != where.end() )
1748 const auto opt = it->second;
1761namespace params_with_opt_value_producer_details
1777 return produce< parameter_with_optional_value_container_t >(
1779 produce< parameter_with_optional_value_t >(
1784 >> ¶meter_with_optional_value_t::first,
1789 >> ¶meter_with_optional_value_t::second,
1791 >> ¶meter_with_optional_value_t::second
1811 :
public producer_tag< parameter_with_optional_value_container_t >
1862inline impl::params_with_opt_value_producer_t
A helper class to automatically return acquired content back to the input stream.
The class that implements "input stream".
RESTINIO_NODISCARD character_t getch() noexcept
Get the next character from the input stream.
void putback() noexcept
Return one character back to the input stream.
RESTINIO_NODISCARD position_t current_position() const noexcept
Get the current position in the stream.
A template for producer of charachers that satisfy some predicate.
Information about parsing error.
Exception class for all exceptions thrown by RESTinio.
A template for a producer that handles possibly empty list of comma-separated values.
Element_Producer m_element
maybe_empty_comma_separated_list_producer_t(Element_Producer &&element)
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from)
A template for a producer that handles non-empty list of comma-separated values.
Element_Producer m_element
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from)
non_empty_comma_separated_list_producer_t(Element_Producer &&element)
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const noexcept
A type of producer that produces instances of parameter_with_optional_value_container.
params_with_opt_value_producer_t()=default
std::decay_t< decltype(params_with_opt_value_producer_details::make_parser()) > actual_producer_t
actual_producer_t m_producer
RESTINIO_NODISCARD auto try_parse(source_t &from)
A type of producer that produces instances of parameter_with_mandatory_value_container.
RESTINIO_NODISCARD auto try_parse(source_t &from)
std::decay_t< decltype(params_with_value_producer_details::make_parser()) > actual_producer_t
actual_producer_t m_producer
params_with_value_producer_t()=default
A producer for quoted_pair.
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const
A producer for quoted_string.
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const
static RESTINIO_NODISCARD optional_t< parse_error_t > try_parse_value(source_t &from, std::string &accumulator)
A helper class to be used to accumulate actual integer while when the next digit is extracted from th...
void consume(zero_initialized_unit_t &dest, char &&digit)
const qvalue_t::underlying_uint_t m_multiplier
constexpr digit_consumer_t(qvalue_t::underlying_uint_t m)
An implementation of producer of qvalue.
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const noexcept
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const
static RESTINIO_NODISCARD optional_t< parse_error_t > try_parse_value(source_t &from, std::string &accumulator)
static RESTINIO_NODISCARD constexpr bool is_token_char(const char ch) noexcept
A helper wrapper to indicate that value is already checked and shouldn't be checked again.
const underlying_uint_t m_value
constexpr trusted(underlying_uint_t value) noexcept
constexpr auto get() const noexcept
A helper wrapper to indicate that value hasn't been checked yet and should be checked in the construc...
auto get() const noexcept
untrusted(underlying_uint_t value)
underlying_uint_t m_value
A class for holding the parsed value of qvalue from RFC7231.
constexpr qvalue_t(qvalue_details::extremum_min_t) noexcept
constexpr auto as_uint() const noexcept
std::array< char, 6 > underlying_char_array_t
underlying_char_array_t make_char_array() const noexcept
static constexpr qvalue_details::extremum_min_t zero
The indicator that tells that new qvalue object should have the minimal allowed value.
constexpr qvalue_t()=default
constexpr qvalue_t(trusted val) noexcept
underlying_uint_t m_value
qvalue_details::underlying_uint_t underlying_uint_t
The type of underlying small integer.
constexpr qvalue_t(qvalue_details::extremum_max_t) noexcept
qvalue_t(untrusted val) noexcept
friend std::ostream & operator<<(std::ostream &to, const qvalue_t &what)
static constexpr qvalue_details::extremum_max_t maximum
The indicator that tells that new qvalue object should have the maximal allowed value.
#define RESTINIO_NODISCARD
An very small, simple and somewhat limited implementation of recursive-descent parser.
const nullopt_t nullopt((nullopt_t::init()))
constexpr char HTAB
A constant for Horizontal Tab value.
RESTINIO_NODISCARD constexpr bool is_space(const char ch) noexcept
If a character a space character?
constexpr char SP
A constant for SPACE value.
RESTINIO_NODISCARD constexpr bool is_digit(const char ch) noexcept
Is a character a decimal digit?
@ consumer
Entity is a consumer of values. It requires a value on the input and doesn't produces anything.
RESTINIO_NODISCARD auto maybe(Clauses &&... clauses)
A factory function to create an optional clause.
RESTINIO_NODISCARD auto symbol(char expected) noexcept
A factory function to create a clause that expects the speficied symbol, extracts it and then skips i...
RESTINIO_NODISCARD auto sequence(Clauses &&... clauses)
A factory function to create a sequence of subclauses.
error_reason_t
Reason of parsing error.
RESTINIO_NODISCARD auto digit() noexcept
A factory function to create a clause that expects a decimal digit, extracts it and then skips it.
RESTINIO_NODISCARD auto repeat(std::size_t min_occurences, std::size_t max_occurences, Clauses &&... clauses)
A factory function to create repetitor of subclauses.
RESTINIO_NODISCARD auto skip() noexcept
A factory function to create a skip_consumer.
RESTINIO_NODISCARD auto custom_consumer(F consumer)
A factory function to create a custom_consumer.
RESTINIO_NODISCARD auto digit_p() noexcept
A factory function to create a digit_producer.
RESTINIO_NODISCARD auto exact_p(string_view_t fragment)
A factory function that creates an instance of exact_fragment_producer.
RESTINIO_NODISCARD auto caseless_symbol(char expected) noexcept
A factory function to create a clause that expects the speficied symbol, extracts it and then skips i...
RESTINIO_NODISCARD auto as_result() noexcept
A factory function to create a as_result_consumer.
constexpr std::size_t N
A special marker that means infinite repetitions.
RESTINIO_NODISCARD auto to_container()
A factory function to create a to_container_consumer.
RESTINIO_NODISCARD auto symbol_p(char expected) noexcept
A factory function to create a symbol_producer.
RESTINIO_NODISCARD auto not_clause(Clauses &&... clauses)
A factory function to create a not_clause.
RESTINIO_NODISCARD auto caseless_exact_p(string_view_t fragment)
A factory function that creates an instance of caseless_exact_fragment_producer.
RESTINIO_NODISCARD auto to_lower() noexcept
A factory function to create a to_lower_transformer.
RESTINIO_NODISCARD auto alternatives(Clauses &&... clauses)
A factory function to create an alternatives clause.
RESTINIO_NODISCARD auto make_parser()
Helper function that creates an instance of producer of parameter_with_optional_value_container.
RESTINIO_NODISCARD auto make_parser()
Helper function that creates an instance of producer of parameter_with_mandatory_value_container.
RESTINIO_NODISCARD constexpr bool is_vchar(const char ch) noexcept
Is a character a VCHAR?
RESTINIO_NODISCARD constexpr bool is_obs_text(const char ch) noexcept
Is a character an obs_text?
RESTINIO_NODISCARD constexpr bool is_alpha(const char ch) noexcept
Is a character an ALPHA?
RESTINIO_NODISCARD constexpr bool is_ctext(const char ch) noexcept
Is a character a ctext?
RESTINIO_NODISCARD constexpr bool is_qdtext(const char ch) noexcept
Is a character a qdtext?
constexpr underlying_uint_t zero
The minimal allowed value for a qvalue.
std::uint_least16_t underlying_uint_t
A type to hold a qvalue.
constexpr underlying_uint_t maximum
The maximal allowed value for a qvalue.
RESTINIO_NODISCARD auto qvalue_p() noexcept
A factory function to create a qvalue_producer.
RESTINIO_NODISCARD auto maybe_empty_comma_separated_list_p(Element_Producer element)
A factory for a producer that handles possibly empty list of comma-separated values.
RESTINIO_NODISCARD auto non_empty_comma_separated_list_p(Element_Producer element)
A factory for a producer that handles non-empty list of comma-separated values.
RESTINIO_NODISCARD auto comment_p()
A factory for producer of comment token.
RESTINIO_NODISCARD auto expected_token_p(string_view_t token)
A factory function to create a producer that expect a token with specific value.
RESTINIO_NODISCARD expected_t< string_view_t, not_found_t > find_first(const parameter_with_mandatory_value_container_t &where, string_view_t what)
A helper function to find the first occurence of a parameter with the specified value.
std::pair< std::string, restinio::optional_t< std::string > > parameter_with_optional_value_t
A type that describes a parameter with optional value.
RESTINIO_NODISCARD impl::params_with_value_producer_t params_with_value_p()
A factory of producer of parameter_with_mandatory_value_container.
std::vector< parameter_with_mandatory_value_t > parameter_with_mandatory_value_container_t
A type of container for parameters with mandatory values.
RESTINIO_NODISCARD auto alphanum_symbol_p()
A factory for producer of symbol that an ALPHA or DIGIT.
RESTINIO_NODISCARD bool operator<(const qvalue_t &a, const qvalue_t &b) noexcept
RESTINIO_NODISCARD auto vchar_symbol_p()
A factory for producer of VCHAR symbols.
RESTINIO_NODISCARD auto alpha_symbol_p()
A factory for producer of ALPHA symbols.
RESTINIO_NODISCARD bool operator==(const qvalue_t &a, const qvalue_t &b) noexcept
RESTINIO_NODISCARD auto ows() noexcept
A factory function to create an OWS clause.
RESTINIO_NODISCARD auto token_p() noexcept
A factory function to create a token_producer.
RESTINIO_NODISCARD impl::params_with_opt_value_producer_t params_with_opt_value_p()
A factory of producer of parameter_with_optional_value_container.
RESTINIO_NODISCARD auto quoted_string_p() noexcept
A factory function to create a quoted_string_producer.
RESTINIO_NODISCARD bool operator!=(const qvalue_t &a, const qvalue_t &b) noexcept
RESTINIO_NODISCARD bool operator<=(const qvalue_t &a, const qvalue_t &b) noexcept
RESTINIO_NODISCARD auto expected_caseless_token_p(string_view_t token)
A factory function to create a producer that expect a token with specific value.
std::pair< std::string, std::string > parameter_with_mandatory_value_t
A type that describes a parameter with mandatory value.
RESTINIO_NODISCARD auto quoted_pair_p() noexcept
A factory function to create a quoted_pair_producer.
std::vector< parameter_with_optional_value_t > parameter_with_optional_value_container_t
A type of container for parameters with optional values.
RESTINIO_NODISCARD auto ctext_symbol_p()
A factory for producer of ctext symbols.
RESTINIO_NODISCARD auto weight_p() noexcept
A factory function to create a producer for weight parameter.
RESTINIO_NODISCARD auto token_symbol_p() noexcept
A factory for producer of symbols than can be used in tokens.
RESTINIO_NODISCARD auto ows_p() noexcept
A factory function to create an ows_producer.
nonstd::string_view string_view_t
nonstd::expected< T, E > expected_t
Helpers for caseless comparison of strings.
One character extracted from the input stream.
A special base class to be used with consumers.
A special base class to be used with producers.
A preducate for symbol_producer_template that checks that a symbol is an alpha.
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
A preducate for symbol_producer_template that checks that a symbol is an alpha or numeric.
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
A preducate for symbol_producer_template that checks that a symbol is a ctext.
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
A predicate for symbol_producer_template that checks that a symbol can be used inside a token.
static RESTINIO_NODISCARD constexpr bool is_token_char(const char ch) noexcept
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
A preducate for symbol_producer_template that checks that a symbol is a VCHAR.
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
qvalue_t::underlying_uint_t m_value
An empty type to be used as indicator of negative search result.