media-type.hpp
Go to the documentation of this file.
/*
* RESTinio
*/
#pragma once
#include <restinio/helpers/http_field_parsers/basics.hpp>
namespace restinio
{
namespace http_field_parsers
{
//
// media_type_value_t
//
struct media_type_value_t
{
using parameter_t = parameter_with_mandatory_value_t;
using parameter_container_t = parameter_with_mandatory_value_container_t;
std::string type;
std::string subtype;
parameter_container_t parameters;
RESTINIO_NODISCARD
static auto
make_default_parser()
{
return produce< media_type_value_t >(
token_p() >> to_lower() >> &media_type_value_t::type,
symbol('/'),
token_p() >> to_lower() >> &media_type_value_t::subtype,
params_with_value_p() >> &media_type_value_t::parameters
);
}
RESTINIO_NODISCARD
static auto
make_weight_aware_parser()
{
return produce< media_type_value_t >(
token_p() >> to_lower() >> &media_type_value_t::type,
symbol('/'),
token_p() >> to_lower() >> &media_type_value_t::subtype,
produce< parameter_container_t >(
repeat( 0, N,
produce< parameter_t >(
not_clause( weight_p() >> skip() ),
ows(),
symbol(';'),
ows(),
token_p() >> to_lower() >> &parameter_t::first,
symbol('='),
alternatives(
token_p() >> &parameter_t::second,
quoted_string_p() >> &parameter_t::second
)
) >> to_container()
)
) >> &media_type_value_t::parameters
);
}
RESTINIO_NODISCARD
static expected_t< media_type_value_t, restinio::easy_parser::parse_error_t >
try_parse( string_view_t what )
{
return restinio::easy_parser::try_parse( what, make_default_parser() );
}
};
} /* namespace http_field_parsers */
} /* namespace restinio */
basics.hpp
Utilities for parsing values of http-fields.
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
restinio::easy_parser::symbol
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...
Definition: easy_parser.hpp:4032
restinio::easy_parser::try_parse
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.
Definition: easy_parser.hpp:5042
restinio::easy_parser::repeat
RESTINIO_NODISCARD auto repeat(std::size_t min_occurences, std::size_t max_occurences, Clauses &&... clauses)
A factory function to create repetitor of subclauses.
Definition: easy_parser.hpp:3876
restinio::easy_parser::skip
RESTINIO_NODISCARD auto skip() noexcept
A factory function to create a skip_consumer.
Definition: easy_parser.hpp:3922
restinio::easy_parser::N
constexpr std::size_t N
A special marker that means infinite repetitions.
Definition: easy_parser.hpp:455
restinio::easy_parser::to_container
RESTINIO_NODISCARD auto to_container()
A factory function to create a to_container_consumer.
Definition: easy_parser.hpp:4583
restinio::easy_parser::not_clause
RESTINIO_NODISCARD auto not_clause(Clauses &&... clauses)
A factory function to create a not_clause.
Definition: easy_parser.hpp:3676
restinio::easy_parser::to_lower
RESTINIO_NODISCARD auto to_lower() noexcept
A factory function to create a to_lower_transformer.
Definition: easy_parser.hpp:4610
restinio::easy_parser::alternatives
RESTINIO_NODISCARD auto alternatives(Clauses &&... clauses)
A factory function to create an alternatives clause.
Definition: easy_parser.hpp:3595
restinio::http_field_parsers::params_with_value_p
RESTINIO_NODISCARD impl::params_with_value_producer_t params_with_value_p()
A factory of producer of parameter_with_mandatory_value_container.
Definition: basics.hpp:1685
restinio::http_field_parsers::parameter_with_mandatory_value_container_t
std::vector< parameter_with_mandatory_value_t > parameter_with_mandatory_value_container_t
A type of container for parameters with mandatory values.
Definition: basics.hpp:1532
restinio::http_field_parsers::ows
RESTINIO_NODISCARD auto ows() noexcept
A factory function to create an OWS clause.
Definition: basics.hpp:939
restinio::http_field_parsers::token_p
RESTINIO_NODISCARD auto token_p() noexcept
A factory function to create a token_producer.
Definition: basics.hpp:985
restinio::http_field_parsers::quoted_string_p
RESTINIO_NODISCARD auto quoted_string_p() noexcept
A factory function to create a quoted_string_producer.
Definition: basics.hpp:1012
restinio::http_field_parsers::parameter_with_mandatory_value_t
std::pair< std::string, std::string > parameter_with_mandatory_value_t
A type that describes a parameter with mandatory value.
Definition: basics.hpp:1521
restinio::http_field_parsers::weight_p
RESTINIO_NODISCARD auto weight_p() noexcept
A factory function to create a producer for weight parameter.
Definition: basics.hpp:1277
restinio
Definition: asio_include.hpp:21
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
restinio::expected_t
nonstd::expected< T, E > expected_t
Definition: expected.hpp:22
restinio::http_field_parsers::media_type_value_t
Tools for working with media-type in HTTP-fields.
Definition: media-type.hpp:42
restinio::http_field_parsers::media_type_value_t::make_weight_aware_parser
static RESTINIO_NODISCARD auto make_weight_aware_parser()
Definition: media-type.hpp:93
restinio::http_field_parsers::media_type_value_t::try_parse
static RESTINIO_NODISCARD expected_t< media_type_value_t, restinio::easy_parser::parse_error_t > try_parse(string_view_t what)
An attempt to parse media-type value.
Definition: media-type.hpp:128
restinio::http_field_parsers::media_type_value_t::make_default_parser
static RESTINIO_NODISCARD auto make_default_parser()
Definition: media-type.hpp:66
restinio::http_field_parsers::media_type_value_t::type
std::string type
Definition: media-type.hpp:47
restinio::http_field_parsers::media_type_value_t::parameter_container_t
parameter_with_mandatory_value_container_t parameter_container_t
Definition: media-type.hpp:45
restinio::http_field_parsers::media_type_value_t::parameters
parameter_container_t parameters
Definition: media-type.hpp:49
restinio::http_field_parsers::media_type_value_t::parameter_t
parameter_with_mandatory_value_t parameter_t
Definition: media-type.hpp:43
restinio::http_field_parsers::media_type_value_t::subtype
std::string subtype
Definition: media-type.hpp:48