GCC Code Coverage Report


Directory: libs/http_proto/
File: include/boost/http_proto/rfc/list_rule.hpp
Date: 2025-09-21 18:08:15
Exec Total Coverage
Lines: 6 6 100.0%
Functions: 3 3 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 //
2 // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.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/url/grammar/range_rule.hpp>
15 #include <boost/core/empty_value.hpp>
16
17 namespace boost {
18 namespace http_proto {
19
20 namespace implementation_defined {
21 template<class Rule>
22 struct list_rule_t
23 : private empty_value<Rule>
24 {
25 using value_type = grammar::range<
26 typename Rule::value_type>;
27
28 constexpr
29 8760 list_rule_t(
30 Rule const& r,
31 std::size_t n,
32 std::size_t m) noexcept
33 : empty_value<Rule>(
34 empty_init, r)
35 8760 , n_(n)
36 8760 , m_(m)
37 {
38 8760 }
39
40 auto
41 parse(
42 char const*& it,
43 char const* end) const ->
44 system::result<value_type>;
45
46 private:
47 struct first_rule;
48 struct next_rule;
49
50 std::size_t n_;
51 std::size_t m_;
52 };
53 } // implementation_defined
54
55 /** Rule for a comma-delimited list of elements
56
57 This rule defines a list containing
58 at least n and at most m of Element,
59 each separated by at least one comma
60 and optional whitespace.
61
62 @par BNF
63 @code
64 #element => [ 1#element ]
65 1#element => element *( OWS "," OWS element )
66 <n>#<m>element => element <n-1>*<m-1>( OWS "," OWS element )
67 @endcode
68
69 Senders must emit compliant values, but
70 receivers should accept values generated
71 with the legacy production rules:
72
73 @par Legacy BNF
74 @code
75 #element => [ ( "," / element ) *( OWS "," [ OWS element ] ) ]
76
77 1#element => *( "," OWS ) element *( OWS "," [ OWS element ] )
78 @endcode
79
80 @tparam Rule The rule type.
81
82 @param r The rule to use for elements.
83 @param n The minimum number of elements, which may be zero.
84 @param m The maximum number of elements.
85
86 @return A rule that matches the list.
87
88 @par Specification
89 @li <a href="https://datatracker.ietf.org/doc/html/rfc7230#section-7"
90 >5.6.1. Lists (#rule ABNF Extension) (rfc7230)</a>
91 */
92 template<class Rule>
93 constexpr
94 auto
95 4530 list_rule(
96 Rule const& r,
97 std::size_t n = 0,
98 std::size_t m =
99 std::size_t(-1)) noexcept ->
100 implementation_defined::list_rule_t<Rule>
101 {
102 4530 return implementation_defined::list_rule_t<Rule>(r, n, m);
103 }
104
105 } // http_proto
106 } // boost
107
108 #include <boost/http_proto/rfc/impl/list_rule.hpp>
109
110 #endif
111