Go to the documentation of this file.
25 namespace http_field_parsers
32 namespace qvalue_details
58 constexpr
auto get()
const noexcept {
return m_value; }
73 "http_field_parser::rfc::qvalue_t" );
160 underlying_char_array_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);
189 : m_value{ val.get() }
193 : m_value{ val.get() }
208 return std::string{ &make_char_array().front() };
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();
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));
363 return (t >= left && t <= right);
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
464 return is_token_char(actual);
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;
539 if( !is_token_char(ch.m_ch) )
542 reason = error_reason_t::unexpected_character;
546 accumulator += ch.m_ch;
550 if( accumulator.empty() )
559 static constexpr
bool
562 return is_token_char_predicate_t::is_token_char( ch );
571 const auto try_result = try_parse_value( from, value );
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();
663 const auto try_result = try_parse_value( from, value );
670 return make_unexpected( *try_result );
675 consumer.started_at(),
676 error_reason_t::unexpected_character
682 consumer.started_at(),
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 );
1185 dest.
m_value += m_multiplier *
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(
1342 m_element >> appender,
1345 maybe(
ows(), m_element >> appender )
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(
1408 maybe(
ows(), m_element >> appender )
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() )
1585 namespace 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 >
1648 return m_producer.try_parse( from );
1684 inline 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;
1761 namespace 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 >
1826 return m_producer.try_parse( from );
1862 inline impl::params_with_opt_value_producer_t
untrusted(underlying_uint_t value)
Exception class for all exceptions thrown by RESTinio.
RESTINIO_NODISCARD auto quoted_string_p() noexcept
A factory function to create a quoted_string_producer.
std::array< char, 6 > underlying_char_array_t
constexpr RESTINIO_NODISCARD bool is_ctext(const char ch) noexcept
Is a character a ctext?
std::decay_t< decltype(params_with_opt_value_producer_details::make_parser()) > actual_producer_t
RESTINIO_NODISCARD auto try_parse(source_t &from)
#define RESTINIO_NODISCARD
RESTINIO_NODISCARD position_t current_position() const noexcept
Get the current position in the stream.
RESTINIO_NODISCARD impl::params_with_value_producer_t params_with_value_p()
A factory of producer of parameter_with_mandatory_value_container.
RESTINIO_NODISCARD auto make_parser()
Helper function that creates an instance of producer of parameter_with_optional_value_container.
A helper wrapper to indicate that value hasn't been checked yet and should be checked in the construc...
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...
A template for producer of charachers that satisfy some predicate.
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.
RESTINIO_NODISCARD auto token_p() noexcept
A factory function to create a token_producer.
A producer for quoted_pair.
RESTINIO_NODISCARD auto expected_token_p(string_view_t token)
A factory function to create a producer that expect a token with specific value.
One character extracted from the input stream.
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from)
static RESTINIO_NODISCARD optional_t< parse_error_t > try_parse_value(source_t &from, std::string &accumulator)
RESTINIO_NODISCARD auto ctext_symbol_p()
A factory for producer of ctext symbols.
RESTINIO_NODISCARD auto token_symbol_p() noexcept
A factory for producer of symbols than can be used in tokens.
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 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.
static RESTINIO_NODISCARD optional_t< parse_error_t > try_parse_value(source_t &from, std::string &accumulator)
constexpr std::size_t N
A special marker that means infinite repetitions.
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...
constexpr underlying_uint_t zero
The minimal allowed value for a qvalue.
RESTINIO_NODISCARD auto not_clause(Clauses &&... clauses)
A factory function to create a not_clause.
RESTINIO_NODISCARD auto digit_p() noexcept
A factory function to create a digit_producer.
RESTINIO_NODISCARD character_t getch() noexcept
Get the next character from the input stream.
RESTINIO_NODISCARD auto comment_p()
A factory for producer of comment token.
Information about parsing error.
static constexpr RESTINIO_NODISCARD bool is_token_char(const char ch) noexcept
constexpr RESTINIO_NODISCARD bool is_vchar(const char ch) noexcept
Is a character a VCHAR?
RESTINIO_NODISCARD bool operator<=(const qvalue_t &a, const qvalue_t &b) noexcept
nonstd::string_view string_view_t
A type of producer that produces instances of parameter_with_mandatory_value_container.
RESTINIO_NODISCARD bool operator!=(const qvalue_t &a, const qvalue_t &b) noexcept
std::pair< std::string, std::string > parameter_with_mandatory_value_t
A type that describes a parameter with mandatory value.
RESTINIO_NODISCARD auto qvalue_p() noexcept
A factory function to create a qvalue_producer.
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
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 try_parse(source_t &from)
const qvalue_t::underlying_uint_t m_multiplier
constexpr RESTINIO_NODISCARD bool is_digit(const char ch) noexcept
Is a character a decimal digit?
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const
RESTINIO_NODISCARD auto as_result() noexcept
A factory function to create a as_result_consumer.
A special base class to be used with consumers.
RESTINIO_NODISCARD auto ows() noexcept
A factory function to create an OWS clause.
RESTINIO_NODISCARD auto symbol_p(char expected) noexcept
A factory function to create a symbol_producer.
A helper wrapper to indicate that value is already checked and shouldn't be checked again.
An implementation of producer of qvalue.
constexpr RESTINIO_NODISCARD bool is_obs_text(const char ch) noexcept
Is a character an obs_text?
An very small, simple and somewhat limited implementation of recursive-descent parser.
std::vector< parameter_with_mandatory_value_t > parameter_with_mandatory_value_container_t
A type of container for parameters with mandatory values.
constexpr qvalue_t(qvalue_details::extremum_min_t) noexcept
qvalue_t::underlying_uint_t m_value
maybe_empty_comma_separated_list_producer_t(Element_Producer &&element)
RESTINIO_NODISCARD auto quoted_pair_p() noexcept
A factory function to create a quoted_pair_producer.
constexpr qvalue_t()=default
params_with_opt_value_producer_t()=default
RESTINIO_NODISCARD auto caseless_exact_p(string_view_t fragment)
A factory function that creates an instance of caseless_exact_fragment_producer.
constexpr qvalue_t(trusted val) noexcept
RESTINIO_NODISCARD expected_t< typename Producer::result_type, parse_error_t > try_parse(string_view_t from, Producer producer)
Perform the parsing of the specified content by using specified value producer.
RESTINIO_NODISCARD bool operator<(const qvalue_t &a, const qvalue_t &b) noexcept
A predicate for symbol_producer_template that checks that a symbol can be used inside a token.
A class for holding the parsed value of qvalue from RFC7231.
RESTINIO_NODISCARD auto weight_p() noexcept
A factory function to create a producer for weight parameter.
RESTINIO_NODISCARD bool operator==(const qvalue_t &a, const qvalue_t &b) noexcept
RESTINIO_NODISCARD auto alpha_symbol_p()
A factory for producer of ALPHA symbols.
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
constexpr char SP
A constant for SPACE value.
constexpr auto as_uint() const noexcept
qvalue_t(untrusted val) noexcept
void consume(zero_initialized_unit_t &dest, char &&digit)
constexpr RESTINIO_NODISCARD bool is_qdtext(const char ch) noexcept
Is a character a qdtext?
constexpr qvalue_t(qvalue_details::extremum_max_t) noexcept
static constexpr RESTINIO_NODISCARD bool is_token_char(const char ch) noexcept
constexpr underlying_uint_t maximum
The maximal allowed value for a qvalue.
constexpr RESTINIO_NODISCARD bool is_space(const char ch) noexcept
If a character a space character?
A helper class to automatically return acquired content back to the input stream.
const nullopt_t nullopt((nullopt_t::init()))
nonstd::expected< T, E > expected_t
constexpr auto get() const noexcept
std::pair< std::string, restinio::optional_t< std::string > > parameter_with_optional_value_t
A type that describes a parameter with optional value.
A producer for quoted_string.
A preducate for symbol_producer_template that checks that a symbol is an alpha or numeric.
A special base class to be used with producers.
A preducate for symbol_producer_template that checks that a symbol is a VCHAR.
RESTINIO_NODISCARD auto to_container()
A factory function to create a to_container_consumer.
auto get() const noexcept
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.
An empty type to be used as indicator of negative search result.
qvalue_details::underlying_uint_t underlying_uint_t
The type of underlying small integer.
RESTINIO_NODISCARD auto ows_p() noexcept
A factory function to create an ows_producer.
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const noexcept
constexpr RESTINIO_NODISCARD bool is_alpha(const char ch) noexcept
Is a character an ALPHA?
std::decay_t< decltype(params_with_value_producer_details::make_parser()) > actual_producer_t
RESTINIO_NODISCARD auto to_lower() noexcept
A factory function to create a to_lower_transformer.
constexpr digit_consumer_t(qvalue_t::underlying_uint_t m)
A type of producer that produces instances of parameter_with_optional_value_container.
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.
Element_Producer m_element
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const noexcept
underlying_char_array_t make_char_array() const noexcept
A template for a producer that handles possibly empty list of comma-separated values.
A template for a producer that handles non-empty list of comma-separated values.
params_with_value_producer_t()=default
error_reason_t
Reason of parsing error.
Helpers for caseless comparison of strings.
A preducate for symbol_producer_template that checks that a symbol is an alpha.
non_empty_comma_separated_list_producer_t(Element_Producer &&element)
constexpr char HTAB
A constant for Horizontal Tab value.
RESTINIO_NODISCARD auto alternatives(Clauses &&... clauses)
A factory function to create an alternatives clause.
RESTINIO_NODISCARD auto exact_p(string_view_t fragment)
A factory function that creates an instance of exact_fragment_producer.
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
std::vector< parameter_with_optional_value_t > parameter_with_optional_value_container_t
A type of container for parameters with optional values.
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const
constexpr trusted(underlying_uint_t value) noexcept
RESTINIO_NODISCARD auto vchar_symbol_p()
A factory for producer of VCHAR symbols.
The class that implements "input stream".
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from)
void putback() noexcept
Return one character back to the input stream.
const underlying_uint_t m_value
Element_Producer m_element
underlying_uint_t m_value
RESTINIO_NODISCARD auto alphanum_symbol_p()
A factory for producer of symbol that an ALPHA or DIGIT.
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
A helper class to be used to accumulate actual integer while when the next digit is extracted from th...
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const
A preducate for symbol_producer_template that checks that a symbol is a ctext.
std::uint_least16_t underlying_uint_t
A type to hold a qvalue.
RESTINIO_NODISCARD auto custom_consumer(F consumer)
A factory function to create a custom_consumer.
RESTINIO_NODISCARD auto sequence(Clauses &&... clauses)
A factory function to create a sequence of subclauses.
std::ostream & operator<<(std::ostream &to, const authorization_value_t::param_value_t &v)
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 maybe(Clauses &&... clauses)
A factory function to create an optional clause.