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
18namespace restinio
19{
20
21namespace http_field_parsers
22{
23
24namespace range_details
25{
26
38template< typename T >
40{
43};
44
56template< typename T >
58{
60};
61
73template< typename T >
75{
77};
78
84template< typename T >
89
95template< 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
125template< typename T >
129
149template< typename T >
151auto
153{
154 return produce< byte_range_spec_t<T> >(
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
183inline auto
185{
186 return sequence( exact( "bytes" ), symbol('=') );
187}
188
208template< typename T >
210auto
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
238inline 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//
285template< 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 >(
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
Utilities for parsing values of http-fields.
#define RESTINIO_NODISCARD
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...
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 auto produce(Clauses &&... clauses)
A factory function to create a producer that creates an instance of the target type by using specifie...
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.
RESTINIO_NODISCARD auto exact(string_view_t fragment)
A factory function that creates an instance of exact_fragment clause.
RESTINIO_NODISCARD auto as_result() noexcept
A factory function to create a as_result_consumer.
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 alternatives(Clauses &&... clauses)
A factory function to create an alternatives clause.
RESTINIO_NODISCARD auto make_byte_range_spec_parser()
Factory for creation of a parser for byte_range_spec values.
Definition: range.hpp:152
RESTINIO_NODISCARD auto make_byte_ranges_specifier_parser()
Factory for creation of a parser for byte_ranges_specifier values.
Definition: range.hpp:211
RESTINIO_NODISCARD auto make_other_ranges_specifier_parser()
Factory for creation of a parser for other_ranges_specifier values.
Definition: range.hpp:239
RESTINIO_NODISCARD auto make_bytes_prefix_parser()
Factory for a parser of 'bytes=' prefix.
Definition: range.hpp:184
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_NODISCARD auto vchar_symbol_p()
A factory for producer of VCHAR symbols.
Definition: basics.hpp:832
RESTINIO_NODISCARD auto token_p() noexcept
A factory function to create a token_producer.
Definition: basics.hpp:985
nonstd::string_view string_view_t
Definition: string_view.hpp:19
nonstd::expected< T, E > expected_t
Definition: expected.hpp:22
A struct that holds a container of byte_range_specs.
Definition: range.hpp:97
Value of range for the case where both ends of the range are defined.
Definition: range.hpp:40
Value of range for the case where only left border of the range is defined.
Definition: range.hpp:58
A description of a range value of units those are not "bytes".
Definition: range.hpp:115
Value of range for the case where only length of range's suffix is defined.
Definition: range.hpp:75
Tools for working with the value of Range HTTP-field.
Definition: range.hpp:287
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
static RESTINIO_NODISCARD auto make_parser()
A factory function for a parser of Range value.
Definition: range.hpp:453