GCC Code Coverage Report


Directory: libs/http_proto/include/boost/http_proto/
File: boost/http_proto/rfc/list_rule.hpp
Date: 2023-02-02 18:17:22
Exec Total Coverage
Lines: 5 5 100.0%
Functions: 2 2 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 //
2 // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/CPPAlliance/http_proto
8 //
9
10 #ifndef BOOST_HTTP_PROTO_RFC_LIST_RULE_HPP
11 #define BOOST_HTTP_PROTO_RFC_LIST_RULE_HPP
12
13 #include <boost/http_proto/detail/config.hpp>
14 #include <boost/http_proto/rfc/detail/rules.hpp>
15 #include <boost/url/grammar/range_rule.hpp>
16 #include <boost/core/empty_value.hpp>
17
18 namespace boost {
19 namespace http_proto {
20
21 /** Rule for a comma-delimited list of elements
22
23 This rule defines a list containing
24 at least n and at most m of Element,
25 each separated by at least one comma
26 and optional whitespace.
27
28 @par BNF
29 @code
30 #element => [ 1#element ]
31 1#element => element *( OWS "," OWS element )
32 <n>#<m>element => element <n-1>*<m-1>( OWS "," OWS element )
33 @endcode
34
35 Senders must emit compliant values, but
36 receivers should accept values generated
37 with the legacy production rules:
38
39 @par Legacy BNF
40 @code
41 #element => [ ( "," / element ) *( OWS "," [ OWS element ] ) ]
42
43 1#element => *( "," OWS ) element *( OWS "," [ OWS element ] )
44 @endcode
45
46 @tparam R The rule to use for elements
47 @tparam N The minimum number of elements, which may be zero
48 @tparam M The maximum number of elements.
49
50 @par Specification
51 @li <a href="https://datatracker.ietf.org/doc/html/rfc7230#section-7"
52 >5.6.1. Lists (#rule ABNF Extension) (rfc7230)</a>
53 */
54 #ifdef BOOST_HTTP_PROTO_DOCS
55 template<class Rule>
56 constexpr
57 __implementation_defined__
58 list_rule(
59 Rule element,
60 std::size_t N = 0,
61 std::size_t M =
62 std::size_t(-1)) noexcept;
63 #else
64 template<class Rule>
65 struct list_rule_t
66 : private empty_value<Rule>
67 {
68 using value_type = grammar::range<
69 typename Rule::value_type>;
70
71 constexpr
72 140 list_rule_t(
73 Rule const& r,
74 std::size_t n,
75 std::size_t m) noexcept
76 : empty_value<Rule>(
77 empty_init, r)
78 , n_(n)
79 140 , m_(m)
80 {
81 140 }
82
83 auto
84 parse(
85 char const*& it,
86 char const* end) const ->
87 result<value_type>;
88
89 private:
90 struct first_rule;
91 struct next_rule;
92
93 std::size_t n_;
94 std::size_t m_;
95 };
96
97 template<class Rule>
98 constexpr
99 auto
100 140 list_rule(
101 Rule const& r,
102 std::size_t N = 0,
103 std::size_t M =
104 std::size_t(-1)) noexcept ->
105 list_rule_t<Rule>
106 {
107 140 return list_rule_t<Rule>(r, N, M);
108 }
109 #endif
110
111 } // http_proto
112 } // boost
113
114 #include <boost/http_proto/rfc/impl/list_rule.hpp>
115
116 #endif
117