28using namespace restinio::easy_parser;
30namespace meta = restinio::utils::metaprogramming;
73 "http_field_parser::rfc::qvalue_t" );
166 static constexpr char fixed_value[]{
"1.000" };
167 std::copy( std::begin(fixed_value), std::end(fixed_value),
168 std::begin(result) );
175 result[2] =
'0' +
static_cast<char>(
m_value / 100u);
176 const auto d2 =
m_value % 100u;
177 result[3] =
'0' +
static_cast<char>(d2 / 10u);
178 const auto d3 = d2 % 10u;
179 result[4] =
'0' +
static_cast<char>(d3);
213 friend std::ostream &
224 return a.as_uint() == b.as_uint();
231 return a.as_uint() != b.as_uint();
238 return a.as_uint() < b.as_uint();
245 return a.as_uint() <= b.as_uint();
267 return (ch >=
'\x41' && ch <=
'\x5A') ||
268 (ch >=
'\x61' && ch <=
'\x7A');
323 return (ch >=
'\x21' && ch <=
'\x7E');
359 constexpr unsigned short left = 0x80u;
360 constexpr unsigned short right = 0xFFu;
362 const unsigned short t =
static_cast<unsigned short>(
363 static_cast<unsigned char>(ch));
365 return (t >= left && t <= right);
385 (ch >=
'\x23' && ch <=
'\x5B') ||
386 (ch >=
'\x5D' && ch <=
'\x7E') ||
406 (ch >=
'\x21' && ch <=
'\x27') ||
407 (ch >=
'\x2A' && ch <=
'\x5B') ||
408 (ch >=
'\x5D' && ch <=
'\x7E') ||
441 static constexpr bool
491 std::size_t extracted_spaces{};
493 for( ch = from.getch();
504 if( extracted_spaces > 0u )
527 static std::optional< parse_error_t >
534 const auto ch = from.
getch();
548 accumulator += ch.m_ch;
552 if( accumulator.empty() )
561 static constexpr bool
575 return { std::move(value) };
577 return make_unexpected( *try_result );
597 static std::optional< parse_error_t >
602 bool second_quote_extracted{
false };
605 const auto ch = from.
getch();
613 second_quote_extracted =
true;
614 else if(
'\\' == ch.m_ch )
616 const auto next = from.
getch();
622 else if(
SP == next.m_ch ||
HTAB == next.m_ch ||
626 accumulator += next.m_ch;
636 accumulator += ch.m_ch;
644 while( !second_quote_extracted );
646 if( !second_quote_extracted )
659 const auto ch = from.
getch();
669 return { std::move(value) };
672 return make_unexpected( *try_result );
714 const auto ch = from.
getch();
717 if(
'\\' == ch.m_ch )
719 const auto next = from.
getch();
722 if(
SP == next.m_ch ||
HTAB == next.m_ch ||
1139 []( std::string & dest, std::string && what ) {
1222 ).try_parse( from );
1227 return make_unexpected( parse_result.error() );
1317 typename Element_Producer >
1322 "Element_Producer should be a value producer type" );
1330 Element_Producer && element )
1338 Container tmp_value;
1342 const auto process_result =
sequence(
1349 ).try_process( from, tmp_value );
1351 if( !process_result )
1352 return { std::move(tmp_value) };
1354 return make_unexpected( *process_result );
1381 typename Element_Producer >
1386 "Element_Producer should be a value producer type" );
1394 Element_Producer && element )
1402 Container tmp_value;
1406 const auto process_result =
maybe(
1412 ).try_process( from, tmp_value );
1414 if( !process_result )
1415 return { std::move(tmp_value) };
1417 return make_unexpected( *process_result );
1456 typename Element_Producer >
1462 "Element_Producer should be a value producer type" );
1466 Element_Producer >{ std::move(element) };
1502 typename Element_Producer >
1508 "Element_Producer should be a value producer type" );
1512 Element_Producer >{ std::move(element) };
1534 std::vector< parameter_with_mandatory_value_t >;
1574 const auto it = std::find_if( where.begin(), where.end(),
1575 [&what](
const auto & pair ) {
1576 return restinio::impl::is_equal_caseless( pair.first, what );
1578 if( it != where.end() )
1610 >> ¶meter_with_mandatory_value_t::first,
1614 >> ¶meter_with_mandatory_value_t::second,
1616 >> ¶meter_with_mandatory_value_t::second
1635 :
public producer_tag< parameter_with_mandatory_value_container_t >
1686inline impl::params_with_value_producer_t
1698 std::pair< std::string, std::optional<std::string> >;
1709 std::vector< parameter_with_optional_value_t >;
1744 const auto it = std::find_if( where.begin(), where.end(),
1745 [&what](
const auto & pair ) {
1746 return restinio::impl::is_equal_caseless( pair.first, what );
1748 if( it != where.end() )
1750 const auto opt = it->second;
1754 return std::optional< string_view_t >{ std::nullopt };
1786 >> ¶meter_with_optional_value_t::first,
1791 >> ¶meter_with_optional_value_t::second,
1793 >> ¶meter_with_optional_value_t::second
1813 :
public producer_tag< parameter_with_optional_value_container_t >
1864inline 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".
position_t current_position() const noexcept
Get the current position in the stream.
void putback() noexcept
Return one character back to the input stream.
character_t getch() noexcept
Get the next character from the input 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)
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
expected_t< result_type, parse_error_t > try_parse(source_t &from)
non_empty_comma_separated_list_producer_t(Element_Producer &&element)
expected_t< result_type, parse_error_t > try_parse(source_t &from) const noexcept
params_with_opt_value_producer_t()=default
auto try_parse(source_t &from)
std::decay_t< decltype(params_with_opt_value_producer_details::make_parser()) > actual_producer_t
actual_producer_t m_producer
auto try_parse(source_t &from)
actual_producer_t m_producer
std::decay_t< decltype(params_with_value_producer_details::make_parser()) > actual_producer_t
params_with_value_producer_t()=default
A producer for quoted_pair.
expected_t< result_type, parse_error_t > try_parse(source_t &from) const
A producer for quoted_string.
expected_t< result_type, parse_error_t > try_parse(source_t &from) const
static std::optional< 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.
expected_t< result_type, parse_error_t > try_parse(source_t &from) const noexcept
expected_t< result_type, parse_error_t > try_parse(source_t &from) const
static std::optional< parse_error_t > try_parse_value(source_t &from, std::string &accumulator)
static 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.
qvalue_details::untrusted untrusted
The type that checks a value to be used for qvalue.
constexpr qvalue_t(qvalue_details::extremum_min_t) noexcept
constexpr auto as_uint() const noexcept
std::array< char, 6 > underlying_char_array_t
qvalue_details::trusted trusted
The type that doesn't check a value to be used for qvalue.
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.
An very small, simple and somewhat limited implementation of recursive-descent parser.
constexpr bool is_producer_v
A meta-value to check whether T is a producer type.
constexpr char HTAB
A constant for Horizontal Tab value.
constexpr char SP
A constant for SPACE value.
@ consumer
Entity is a consumer of values. It requires a value on the input and doesn't produces anything.
constexpr bool is_space(const char ch) noexcept
If a character a space character?
constexpr bool is_digit(const char ch) noexcept
Is a character a decimal digit?
auto digit_p() noexcept
A factory function to create a digit_producer.
auto to_container()
A factory function to create a to_container_consumer.
auto symbol(char expected) noexcept
A factory function to create a clause that expects the speficied symbol, extracts it and then skips i...
auto digit() noexcept
A factory function to create a clause that expects a decimal digit, extracts it and then skips it.
auto as_result() noexcept
A factory function to create a as_result_consumer.
auto maybe(Clauses &&... clauses)
A factory function to create an optional clause.
auto skip() noexcept
A factory function to create a skip_consumer.
error_reason_t
Reason of parsing error.
@ unexpected_eof
Unexpected end of input is encontered when some character expected.
@ unexpected_character
Unexpected character is found in the input.
@ pattern_not_found
Required pattern is not found in the input.
auto symbol_p(char expected) noexcept
A factory function to create a symbol_producer.
auto to_lower() noexcept
A factory function to create a to_lower_transformer.
auto caseless_symbol(char expected) noexcept
A factory function to create a clause that expects the speficied symbol, extracts it and then skips i...
auto alternatives(Clauses &&... clauses)
A factory function to create an alternatives clause.
auto produce(Clauses &&... clauses)
A factory function to create a producer that creates an instance of the target type by using specifie...
auto not_clause(Clauses &&... clauses)
A factory function to create a not_clause.
auto caseless_exact_p(string_view_t fragment)
A factory function that creates an instance of caseless_exact_fragment_producer.
constexpr std::size_t N
A special marker that means infinite repetitions.
auto exact_p(string_view_t fragment)
A factory function that creates an instance of exact_fragment_producer.
auto repeat(std::size_t min_occurences, std::size_t max_occurences, Clauses &&... clauses)
A factory function to create repetitor of subclauses.
auto sequence(Clauses &&... clauses)
A factory function to create a sequence of subclauses.
auto custom_consumer(F consumer)
A factory function to create a custom_consumer.
auto make_parser()
Helper function that creates an instance of producer of parameter_with_optional_value_container.
auto make_parser()
Helper function that creates an instance of producer of parameter_with_mandatory_value_container.
constexpr bool is_qdtext(const char ch) noexcept
Is a character a qdtext?
constexpr bool is_ctext(const char ch) noexcept
Is a character a ctext?
constexpr bool is_obs_text(const char ch) noexcept
Is a character an obs_text?
constexpr bool is_vchar(const char ch) noexcept
Is a character a VCHAR?
constexpr bool is_alpha(const char ch) noexcept
Is a character an ALPHA?
std::uint_least16_t underlying_uint_t
A type to hold a qvalue.
constexpr underlying_uint_t zero
The minimal allowed value for a qvalue.
constexpr underlying_uint_t maximum
The maximal allowed value for a qvalue.
impl::params_with_value_producer_t params_with_value_p()
A factory of producer of parameter_with_mandatory_value_container.
auto maybe_empty_comma_separated_list_p(Element_Producer element)
A factory for a producer that handles possibly empty list of comma-separated values.
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.
auto vchar_symbol_p()
A factory for producer of VCHAR symbols.
auto qvalue_p() noexcept
A factory function to create a qvalue_producer.
auto ows_p() noexcept
A factory function to create an ows_producer.
auto token_p() noexcept
A factory function to create a token_producer.
auto ctext_symbol_p()
A factory for producer of ctext symbols.
bool operator==(const qvalue_t &a, const qvalue_t &b) noexcept
auto expected_token_p(string_view_t token)
A factory function to create a producer that expect a token with specific value.
auto non_empty_comma_separated_list_p(Element_Producer element)
A factory for a producer that handles non-empty list of comma-separated values.
std::vector< parameter_with_optional_value_t > parameter_with_optional_value_container_t
A type of container for parameters with optional values.
auto alpha_symbol_p()
A factory for producer of ALPHA symbols.
auto token_symbol_p() noexcept
A factory for producer of symbols than can be used in tokens.
bool operator!=(const qvalue_t &a, const qvalue_t &b) noexcept
std::pair< std::string, std::optional< std::string > > parameter_with_optional_value_t
A type that describes a parameter with optional value.
auto alphanum_symbol_p()
A factory for producer of symbol that an ALPHA or DIGIT.
bool operator<=(const qvalue_t &a, const qvalue_t &b) noexcept
auto weight_p() noexcept
A factory function to create a producer for weight parameter.
auto ows() noexcept
A factory function to create an OWS clause.
std::pair< std::string, std::string > parameter_with_mandatory_value_t
A type that describes a parameter with mandatory value.
auto quoted_pair_p() noexcept
A factory function to create a quoted_pair_producer.
impl::params_with_opt_value_producer_t params_with_opt_value_p()
A factory of producer of parameter_with_optional_value_container.
bool operator<(const qvalue_t &a, const qvalue_t &b) noexcept
auto quoted_string_p() noexcept
A factory function to create a quoted_string_producer.
auto comment_p()
A factory for producer of comment token.
auto expected_caseless_token_p(string_view_t token)
A factory function to create a producer that expect a token with specific value.
std::vector< parameter_with_mandatory_value_t > parameter_with_mandatory_value_container_t
A type of container for parameters with mandatory values.
std::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.
std::optional< char > result_type
A preducate for symbol_producer_template that checks that a symbol is an alpha.
bool operator()(const char actual) const noexcept
A preducate for symbol_producer_template that checks that a symbol is an alpha or numeric.
bool operator()(const char actual) const noexcept
A preducate for symbol_producer_template that checks that a symbol is a ctext.
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 constexpr bool is_token_char(const char ch) noexcept
bool operator()(const char actual) const noexcept
A preducate for symbol_producer_template that checks that a symbol is a VCHAR.
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.