RESTinio
content-disposition.hpp
Go to the documentation of this file.
1/*
2 * RESTinio
3 */
4
12#pragma once
13
15
17
18namespace restinio
19{
20
21namespace http_field_parsers
22{
23
24namespace content_disposition_details
25{
26
30
31//
32// regular_token_producer_t
33//
47{
48public:
52 {
53 ep_impl::source_t::content_consumer_t consumer{ from };
54 const auto result = hfp_impl::token_producer_t::try_parse( from );
55 if( result )
56 {
57 if( '*' == *(result->rbegin()) )
58 {
59 // Regular token can't have the trailing '*'.
60 return make_unexpected( parse_error_t{
61 consumer.started_at() + result->size() - 1,
62 error_reason_t::unexpected_character
63 } );
64 }
65
66 consumer.commit();
67 }
68
69 return result;
70 }
71};
72
73//
74// ext_token_producer_t
75//
89{
90public:
94 {
95 ep_impl::source_t::content_consumer_t consumer{ from };
96 const auto result = hfp_impl::token_producer_t::try_parse( from );
97 if( result )
98 {
99 if( '*' != *(result->rbegin()) )
100 {
101 // Extended token should have the trailing '*'.
102 return make_unexpected( parse_error_t{
103 consumer.started_at(),
104 error_reason_t::pattern_not_found
105 } );
106 }
107
108 consumer.commit();
109 }
110
111 return result;
112 }
113};
114
115//
116// mime_charsetc_predicate_t
117//
127{
129 bool
130 operator()( const char actual ) const noexcept
131 {
132 return hfp_impl::is_alpha(actual)
133 || hfp_impl::is_digit(actual)
134 || '!' == actual
135 || '#' == actual
136 || '$' == actual
137 || '%' == actual
138 || '&' == actual
139 || '+' == actual
140 || '-' == actual
141 || '^' == actual
142 || '_' == actual
143 || '`' == actual
144 || '{' == actual
145 || '}' == actual
146 || '~' == actual
147 ;
148 }
149};
150
151//
152// mime_charsetc_symbol_producer
153//
162inline auto
164{
166}
167
168//
169// language_predicate_t
170//
185{
187 bool
188 operator()( const char actual ) const noexcept
189 {
190 return hfp_impl::is_alpha(actual)
191 || hfp_impl::is_digit(actual)
192 || '-' == actual
193 ;
194 }
195};
196
197//
198// language_symbol_producer
199//
206inline auto
208{
210}
211
212//
213// attr_char_predicate_t
214//
224{
226 bool
227 operator()( const char actual ) const noexcept
228 {
229 return hfp_impl::is_alpha(actual)
230 || hfp_impl::is_digit(actual)
231 || '!' == actual
232 || '#' == actual
233 || '$' == actual
234 || '&' == actual
235 || '+' == actual
236 || '-' == actual
237 || '.' == actual
238 || '^' == actual
239 || '_' == actual
240 || '`' == actual
241 || '|' == actual
242 || '~' == actual
243 ;
244 }
245};
246
247//
248// attr_char_symbol_producer
249//
258inline auto
260{
262}
263
264//
265// ext_parameter_value_producer
266//
298inline auto
300{
301 return produce< std::string >(
303 symbol_p( '\'' ) >> to_container(),
305 symbol_p( '\'' ) >> to_container(),
306 repeat( 0, N,
311 )
312 );
313}
314
315} /* namespace content_disposition_details */
316
317//
318// content_disposition_value_t
319//
337{
339
341
342 std::string value;
344
351 static auto
353 {
354 using namespace content_disposition_details;
355
356 return produce< content_disposition_value_t >(
357 token_p() >> to_lower()
359 produce< parameter_container_t >(
360 repeat( 0, N,
361 produce< parameter_t >(
362 ows(),
363 symbol(';'),
364 ows(),
366 sequence(
367 regular_token_producer_t{}
368 >> to_lower() >> &parameter_t::first,
369 symbol('='),
371 token_p() >> &parameter_t::second,
372 quoted_string_p() >> &parameter_t::second
373 )
374 ),
375 sequence(
376 ext_token_producer_t{}
377 >> to_lower() >> &parameter_t::first,
378 symbol('='),
379 ext_parameter_value_p() >> &parameter_t::second
380 )
381 )
382 ) >> to_container()
383 )
385 );
386 }
387
396 {
398 }
399};
400
401} /* namespace http_field_parsers */
402
403} /* namespace restinio */
404
Utilities for parsing values of http-fields.
The class that implements "input stream".
A template for producer of charachers that satisfy some predicate.
Information about parsing error.
Definition: easy_parser.hpp:93
A producer for token that is an "extended parameter name" in sense of RCF6266 and RCF5987.
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(ep_impl::source_t &from) const
A producer for token that is a "regular parameter name" in sense of RCF6266 and RCF5987.
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(ep_impl::source_t &from) const
RESTINIO_NODISCARD expected_t< result_type, parse_error_t > try_parse(source_t &from) const
Definition: basics.hpp:568
#define RESTINIO_NODISCARD
RESTINIO_NODISCARD constexpr bool is_digit(const char ch) noexcept
Is a character a decimal digit?
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.
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 auto repeat(std::size_t min_occurences, std::size_t max_occurences, Clauses &&... clauses)
A factory function to create repetitor of subclauses.
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 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 mime_charsetc_symbol_p()
A factory for producer that extracts mime-charsetc symbols.
RESTINIO_NODISCARD auto language_symbol_p()
A factory for producer that extracts language symbols.
RESTINIO_NODISCARD auto attr_char_symbol_p()
A factory for producer that extracts attr-char symbols.
RESTINIO_NODISCARD auto ext_parameter_value_p()
A producer for an "extended parameter value" in sense of RCF6266 and RCF5987.
RESTINIO_NODISCARD auto pct_encoded_symbols_p()
A producer that extract a sequence of symbols represented a percent-encoded character.
RESTINIO_NODISCARD constexpr bool is_alpha(const char ch) noexcept
Is a character an ALPHA?
Definition: basics.hpp:263
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_NODISCARD auto ows() noexcept
A factory function to create an OWS clause.
Definition: basics.hpp:939
RESTINIO_NODISCARD auto token_p() noexcept
A factory function to create a token_producer.
Definition: basics.hpp:985
RESTINIO_NODISCARD auto quoted_string_p() noexcept
A factory function to create a quoted_string_producer.
Definition: basics.hpp:1012
std::pair< std::string, std::string > parameter_with_mandatory_value_t
A type that describes a parameter with mandatory value.
Definition: basics.hpp:1521
nonstd::string_view string_view_t
Definition: string_view.hpp:19
nonstd::expected< T, E > expected_t
Definition: expected.hpp:22
Stuff related to percent-encoded symbols.
A preducate for symbol_producer_template that checks that a symbol is attr-char symbol from RCF5987.
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
A preducate for symbol_producer_template that checks that a symbol is language symbol from RCF5646.
RESTINIO_NODISCARD bool operator()(const char actual) const noexcept
A preducate for symbol_producer_template that checks that a symbol is mime-charsetc symbol from RCF59...
Tools for working with the value of Content-Disposition HTTP-field.
static RESTINIO_NODISCARD expected_t< content_disposition_value_t, restinio::easy_parser::parse_error_t > try_parse(string_view_t what)
An attempt to parse Content-Disposition HTTP-field.
parameter_with_mandatory_value_container_t parameter_container_t
static RESTINIO_NODISCARD auto make_parser()
A factory function for a parser of Content-Disposition value.
A special consumer that inserts an extracted sequence of symbols into the result string.