RESTinio
range.hpp
Go to the documentation of this file.
1 /*
2  * RESTinio
3  */
4 
12 #pragma once
13 
15 
16 #include <restinio/variant.hpp>
17 
18 namespace restinio
19 {
20 
21 namespace http_field_parsers
22 {
23 
24 namespace range_details
25 {
26 
38 template< typename T >
40 {
41  T first;
42  T last;
43 };
44 
56 template< typename T >
58 {
59  T first;
60 };
61 
73 template< typename T >
75 {
76  T length;
77 };
78 
84 template< typename T >
89 
95 template< typename T >
97 {
98  std::vector< byte_range_spec_t<T> > ranges;
99 };
100 
115 {
116  std::string range_unit;
117  std::string range_set;
118 };
119 
125 template< typename T >
129 
149 template< typename T >
151 auto
153 {
154  return produce< byte_range_spec_t<T> >(
155  alternatives(
157  non_negative_decimal_number_p<T>()
159  symbol('-'),
160  non_negative_decimal_number_p<T>()
162  ) >> as_result(),
164  non_negative_decimal_number_p<T>()
166  symbol('-')
167  ) >> as_result(),
169  symbol('-'),
170  non_negative_decimal_number_p<T>()
172  ) >> as_result()
173  )
174  );
175 }
176 
183 inline auto
185 {
186  return sequence( exact( "bytes" ), symbol('=') );
187 }
188 
208 template< typename T >
210 auto
212 {
213  return produce< byte_ranges_specifier_t<T> >(
217  std::vector< byte_range_spec_t<T> > >(
218  make_byte_range_spec_parser<T>()
220  )
221  );
222 }
223 
238 inline auto
240 {
241  return produce< other_ranges_specifier_t >(
243  symbol('='),
245  produce< std::string >(
246  repeat( 1u, N, vchar_symbol_p() >> to_container() )
248  )
249  );
250 }
251 
252 } /* namespace range_details */
253 
254 //
255 // range_value_t
256 //
285 template< typename T >
287 {
319 
350 
382 
389 
421 
436 
443 
445 
452  static auto
454  {
455  using namespace range_details;
456 
457  return produce< range_value_t >(
458  alternatives(
459  make_byte_ranges_specifier_parser<T>() >>
463  )
464  );
465  }
466 
475  {
477  }
478 };
479 
480 } /* namespace http_field_parsers */
481 
482 } /* namespace restinio */
483 
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::http_field_parsers::range_details::byte_ranges_specifier_t::ranges
std::vector< byte_range_spec_t< T > > ranges
Definition: range.hpp:98
restinio::easy_parser::produce
RESTINIO_NODISCARD auto produce(Clauses &&... clauses)
A factory function to create a producer that creates an instance of the target type by using specifie...
Definition: easy_parser.hpp:3554
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::http_field_parsers::range_value_t::make_parser
static RESTINIO_NODISCARD auto make_parser()
A factory function for a parser of Range value.
Definition: range.hpp:453
restinio::http_field_parsers::range_details::make_other_ranges_specifier_parser
RESTINIO_NODISCARD auto make_other_ranges_specifier_parser()
Factory for creation of a parser for other_ranges_specifier values.
Definition: range.hpp:239
restinio::string_view_t
nonstd::string_view string_view_t
Definition: string_view.hpp:19
restinio::http_field_parsers::range_details::double_ended_range_t::first
T first
Definition: range.hpp:41
restinio::easy_parser::force_only_this_alternative
RESTINIO_NODISCARD auto force_only_this_alternative(Clauses &&... clauses)
An alternative that should be parsed correctly or the parsing of the whole alternatives clause should...
Definition: easy_parser.hpp:3821
restinio::easy_parser::as_result
RESTINIO_NODISCARD auto as_result() noexcept
A factory function to create a as_result_consumer.
Definition: easy_parser.hpp:4470
restinio::http_field_parsers::range_details::make_byte_range_spec_parser
RESTINIO_NODISCARD auto make_byte_range_spec_parser()
Factory for creation of a parser for byte_range_spec values.
Definition: range.hpp:152
restinio::http_field_parsers::range_details::other_ranges_specifier_t::range_unit
std::string range_unit
Definition: range.hpp:116
restinio::http_field_parsers::range_details::make_bytes_prefix_parser
RESTINIO_NODISCARD auto make_bytes_prefix_parser()
Factory for a parser of 'bytes=' prefix.
Definition: range.hpp:184
restinio::http_field_parsers::range_details::double_ended_range_t
Value of range for the case where both ends of the range are defined.
Definition: range.hpp:40
restinio::http_field_parsers::range_details::double_ended_range_t::last
T last
Definition: range.hpp:42
restinio::http_field_parsers::range_details::byte_ranges_specifier_t
A struct that holds a container of byte_range_specs.
Definition: range.hpp:97
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::range_value_t::value
value_t value
Definition: range.hpp:444
restinio::http_field_parsers::range_details::suffix_length_t::length
T length
Definition: range.hpp:76
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::http_field_parsers::range_details::make_byte_ranges_specifier_parser
RESTINIO_NODISCARD auto make_byte_ranges_specifier_parser()
Factory for creation of a parser for byte_ranges_specifier values.
Definition: range.hpp:211
restinio::http_field_parsers::range_details::open_ended_range_t::first
T first
Definition: range.hpp:59
restinio::easy_parser::exact
RESTINIO_NODISCARD auto exact(string_view_t fragment)
A factory function that creates an instance of exact_fragment clause.
Definition: easy_parser.hpp:4833
restinio
Definition: asio_include.hpp:21
restinio::http_field_parsers::range_details::suffix_length_t
Value of range for the case where only length of range's suffix is defined.
Definition: range.hpp:75
restinio::http_field_parsers::non_empty_comma_separated_list_p
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.
Definition: basics.hpp:1457
restinio::http_field_parsers::range_value_t
Tools for working with the value of Range HTTP-field.
Definition: range.hpp:287
restinio::http_field_parsers::range_details::open_ended_range_t
Value of range for the case where only left border of the range is defined.
Definition: range.hpp:58
restinio::http_field_parsers::range_details::other_ranges_specifier_t::range_set
std::string range_set
Definition: range.hpp:117
restinio::easy_parser::alternatives
RESTINIO_NODISCARD auto alternatives(Clauses &&... clauses)
A factory function to create an alternatives clause.
Definition: easy_parser.hpp:3595
variant.hpp
restinio::http_field_parsers::vchar_symbol_p
RESTINIO_NODISCARD auto vchar_symbol_p()
A factory for producer of VCHAR symbols.
Definition: basics.hpp:832
restinio::http_field_parsers::range_details::other_ranges_specifier_t
A description of a range value of units those are not "bytes".
Definition: range.hpp:115
nonstd::variants::variant
Definition: variant.hpp:1209
restinio::easy_parser::sequence
RESTINIO_NODISCARD auto sequence(Clauses &&... clauses)
A factory function to create a sequence of subclauses.
Definition: easy_parser.hpp:3758
restinio::http_field_parsers::range_value_t::try_parse
static RESTINIO_NODISCARD expected_t< range_value_t, restinio::easy_parser::parse_error_t > try_parse(string_view_t what)
An attempt to parse Range HTTP-field.
Definition: range.hpp:474
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