RESTinio
media-type.hpp
Go to the documentation of this file.
1 /*
2  * RESTinio
3  */
4 
12 #pragma once
13 
15 
16 namespace restinio
17 {
18 
19 namespace http_field_parsers
20 {
21 
22 //
23 // media_type_value_t
24 //
42 {
44 
46 
47  std::string type;
48  std::string subtype;
50 
65  static auto
67  {
68  return produce< media_type_value_t >(
70  symbol('/'),
73  );
74  }
75 
92  static auto
94  {
95  return produce< media_type_value_t >(
97  symbol('/'),
99  produce< parameter_container_t >(
100  repeat( 0, N,
101  produce< parameter_t >(
102  not_clause( weight_p() >> skip() ),
103  ows(),
104  symbol(';'),
105  ows(),
106  token_p() >> to_lower() >> &parameter_t::first,
107  symbol('='),
108  alternatives(
109  token_p() >> &parameter_t::second,
110  quoted_string_p() >> &parameter_t::second
111  )
112  ) >> to_container()
113  )
115  );
116  }
117 
129  {
131  }
132 };
133 
134 } /* namespace http_field_parsers */
135 
136 } /* namespace restinio */
137 
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_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
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::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::http_field_parsers::media_type_value_t::parameters
parameter_container_t parameters
Definition: media-type.hpp:49
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::easy_parser::N
constexpr std::size_t N
A special marker that means infinite repetitions.
Definition: easy_parser.hpp:455
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::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::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
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::ows
RESTINIO_NODISCARD auto ows() noexcept
A factory function to create an OWS clause.
Definition: basics.hpp:939
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::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::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::weight_p
RESTINIO_NODISCARD auto weight_p() noexcept
A factory function to create a producer for weight parameter.
Definition: basics.hpp:1277
restinio::http_field_parsers::media_type_value_t
Tools for working with media-type in HTTP-fields.
Definition: media-type.hpp:42
restinio::expected_t
nonstd::expected< T, E > expected_t
Definition: expected.hpp:22
basics.hpp
Utilities for parsing values of http-fields.
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
Definition: asio_include.hpp:21
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::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::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::parameter_t
parameter_with_mandatory_value_t parameter_t
Definition: media-type.hpp:43
restinio::http_field_parsers::media_type_value_t::type
std::string type
Definition: media-type.hpp:47
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::http_field_parsers::media_type_value_t::subtype
std::string subtype
Definition: media-type.hpp:48