include/boost/http/rfc/impl/list_rule.hpp
98.2% Lines (56/57)
100.0% List of functions (16/16)
Functions (16)
Function
Calls
Lines
Blocks
boost::http::detail::ows_comma_t::parse(char const*&, char const*) const
:44
98x
100.0%
100.0%
boost::http::implementation_defined::list_rule_t<boost::http::detail::transfer_coding_rule_t>::first_rule::first_rule(boost::http::detail::transfer_coding_rule_t const&)
:91
4447x
100.0%
100.0%
boost::http::implementation_defined::list_rule_t<boost::http::implementation_defined::upgrade_protocol_rule_t>::first_rule::first_rule(boost::http::implementation_defined::upgrade_protocol_rule_t const&)
:91
31x
100.0%
100.0%
boost::http::implementation_defined::list_rule_t<boost::urls::grammar::implementation_defined::token_rule_t<boost::urls::grammar::lut_chars> >::first_rule::first_rule(boost::urls::grammar::implementation_defined::token_rule_t<boost::urls::grammar::lut_chars> const&)
:91
181x
100.0%
100.0%
boost::http::implementation_defined::list_rule_t<boost::http::detail::transfer_coding_rule_t>::first_rule::parse(char const*&, char const*) const
:99
8857x
52.4%
56.0%
boost::http::implementation_defined::list_rule_t<boost::http::implementation_defined::upgrade_protocol_rule_t>::first_rule::parse(char const*&, char const*) const
:99
47x
52.6%
59.0%
boost::http::implementation_defined::list_rule_t<boost::urls::grammar::implementation_defined::token_rule_t<boost::urls::grammar::lut_chars> >::first_rule::parse(char const*&, char const*) const
:99
352x
100.0%
97.0%
boost::http::implementation_defined::list_rule_t<boost::http::detail::transfer_coding_rule_t>::next_rule::next_rule(boost::http::detail::transfer_coding_rule_t const&)
:144
4447x
100.0%
100.0%
boost::http::implementation_defined::list_rule_t<boost::http::implementation_defined::upgrade_protocol_rule_t>::next_rule::next_rule(boost::http::implementation_defined::upgrade_protocol_rule_t const&)
:144
31x
100.0%
100.0%
boost::http::implementation_defined::list_rule_t<boost::urls::grammar::implementation_defined::token_rule_t<boost::urls::grammar::lut_chars> >::next_rule::next_rule(boost::urls::grammar::implementation_defined::token_rule_t<boost::urls::grammar::lut_chars> const&)
:144
181x
100.0%
100.0%
boost::http::implementation_defined::list_rule_t<boost::http::detail::transfer_coding_rule_t>::next_rule::parse(char const*&, char const*) const
:152
8869x
100.0%
91.0%
boost::http::implementation_defined::list_rule_t<boost::http::implementation_defined::upgrade_protocol_rule_t>::next_rule::parse(char const*&, char const*) const
:152
34x
92.9%
80.0%
boost::http::implementation_defined::list_rule_t<boost::urls::grammar::implementation_defined::token_rule_t<boost::urls::grammar::lut_chars> >::next_rule::parse(char const*&, char const*) const
:152
371x
100.0%
100.0%
boost::http::implementation_defined::list_rule_t<boost::http::detail::transfer_coding_rule_t>::parse(char const*&, char const*) const
:184
33x
100.0%
83.0%
boost::http::implementation_defined::list_rule_t<boost::http::implementation_defined::upgrade_protocol_rule_t>::parse(char const*&, char const*) const
:184
7x
100.0%
83.0%
boost::http::implementation_defined::list_rule_t<boost::urls::grammar::implementation_defined::token_rule_t<boost::urls::grammar::lut_chars> >::parse(char const*&, char const*) const
:184
91x
100.0%
83.0%
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 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 | ||
| 8 | // | ||
| 9 | |||
| 10 | #ifndef BOOST_HTTP_RFC_IMPL_LIST_RULE_HPP | ||
| 11 | #define BOOST_HTTP_RFC_IMPL_LIST_RULE_HPP | ||
| 12 | |||
| 13 | #include <boost/http/rfc/detail/ws.hpp> | ||
| 14 | |||
| 15 | #include <boost/url/grammar/parse.hpp> | ||
| 16 | #include <boost/url/grammar/charset.hpp> | ||
| 17 | #include <boost/url/grammar/range_rule.hpp> | ||
| 18 | #include <boost/core/empty_value.hpp> | ||
| 19 | |||
| 20 | namespace boost { | ||
| 21 | namespace http { | ||
| 22 | |||
| 23 | namespace detail { | ||
| 24 | |||
| 25 | /* Peter: | ||
| 26 | |||
| 27 | So, to put everything together, this is what I propose | ||
| 28 | |||
| 29 | - make range2_rule that takes first and next with | ||
| 30 | value types of optional<E> rather than E like the current rule | ||
| 31 | - make variant_rule produce an optional<X> when otherwise | ||
| 32 | the value type would have been variant<void, void, X, void> | ||
| 33 | - add operators for combining the rules so that one can | ||
| 34 | write *( OWS >> !literal(",") >> -( OWS >> element ) ) | ||
| 35 | - profit | ||
| 36 | */ | ||
| 37 | |||
| 38 | // *( OWS "," ) | ||
| 39 | struct ows_comma_t | ||
| 40 | { | ||
| 41 | using value_type = void; | ||
| 42 | |||
| 43 | auto | ||
| 44 | 98x | parse( | |
| 45 | char const*& it, | ||
| 46 | char const* end) const noexcept -> | ||
| 47 | system::result<value_type> | ||
| 48 | { | ||
| 49 | 98x | auto it1 = it; | |
| 50 | 246x | while(it != end) | |
| 51 | { | ||
| 52 | // SP / HT | ||
| 53 | 231x | if( *it == ' ' || | |
| 54 | 173x | *it == '\t') | |
| 55 | { | ||
| 56 | 60x | ++it; | |
| 57 | 60x | continue; | |
| 58 | } | ||
| 59 | 171x | if(*it != ',') | |
| 60 | 83x | break; | |
| 61 | // "," | ||
| 62 | 88x | it1 = ++it; | |
| 63 | } | ||
| 64 | 98x | it = it1; | |
| 65 | 98x | return {}; | |
| 66 | } | ||
| 67 | }; | ||
| 68 | |||
| 69 | constexpr ows_comma_t ows_comma{}; | ||
| 70 | |||
| 71 | } // detail | ||
| 72 | |||
| 73 | /* | ||
| 74 | #element => [ ( "," / element ) *( OWS "," [ OWS element ] ) ] | ||
| 75 | |||
| 76 | #element => first *next | ||
| 77 | first => [ element / ( "," *( OWS "," ) [ OWS element ] ) ] | ||
| 78 | next => "" / ( 1*( OWS "," ) [ OWS element ] ) | ||
| 79 | */ | ||
| 80 | |||
| 81 | namespace implementation_defined { | ||
| 82 | template<class Rule> | ||
| 83 | struct list_rule_t<Rule>:: | ||
| 84 | first_rule : empty_value<Rule> | ||
| 85 | { | ||
| 86 | using value_type = | ||
| 87 | typename Rule::value_type; | ||
| 88 | |||
| 89 | constexpr | ||
| 90 | explicit | ||
| 91 | 4659x | first_rule( | |
| 92 | Rule const& r) noexcept | ||
| 93 | : empty_value<Rule>( | ||
| 94 | 4659x | empty_init, r) | |
| 95 | { | ||
| 96 | 4659x | } | |
| 97 | |||
| 98 | auto | ||
| 99 | 9256x | parse( | |
| 100 | char const*& it, | ||
| 101 | char const* end) const -> | ||
| 102 | system::result<value_type> | ||
| 103 | { | ||
| 104 | // first => [ element / ( "," *( OWS "," ) [ OWS element ] ) ] | ||
| 105 | |||
| 106 | 9256x | if(it == end) | |
| 107 | 7x | return grammar::error::end_of_range; | |
| 108 | { | ||
| 109 | // element | ||
| 110 | 9249x | auto it0 = it; | |
| 111 | 9249x | auto rv = this->get().parse(it, end); | |
| 112 | 9249x | if(rv) | |
| 113 | 9221x | return std::move(*rv); | |
| 114 | 28x | it = it0; | |
| 115 | 8856x | } | |
| 116 | // "," | ||
| 117 | 28x | if(*it != ',') | |
| 118 | 15x | return grammar::error::end_of_range; | |
| 119 | 13x | ++it; | |
| 120 | // *( OWS "," ) | ||
| 121 | 13x | detail::ows_comma.parse(it, end); | |
| 122 | 13x | auto it1 = it; | |
| 123 | // OWS | ||
| 124 | 13x | it = grammar::find_if_not( | |
| 125 | it, end, detail::ws); | ||
| 126 | // element | ||
| 127 | 13x | auto rv = this->get().parse(it, end); | |
| 128 | 13x | if(rv) | |
| 129 | 6x | return std::move(*rv); | |
| 130 | 7x | it = it1; | |
| 131 | 7x | return grammar::error::end_of_range; | |
| 132 | ✗ | } | |
| 133 | }; | ||
| 134 | |||
| 135 | template<class Rule> | ||
| 136 | struct list_rule_t<Rule>:: | ||
| 137 | next_rule : empty_value<Rule> | ||
| 138 | { | ||
| 139 | using value_type = | ||
| 140 | typename Rule::value_type; | ||
| 141 | |||
| 142 | constexpr | ||
| 143 | explicit | ||
| 144 | 4659x | next_rule( | |
| 145 | Rule const& r) noexcept | ||
| 146 | : empty_value<Rule>( | ||
| 147 | 4659x | empty_init, r) | |
| 148 | { | ||
| 149 | 4659x | } | |
| 150 | |||
| 151 | auto | ||
| 152 | 9274x | parse( | |
| 153 | char const*& it, | ||
| 154 | char const* end) const -> | ||
| 155 | system::result<value_type> | ||
| 156 | { | ||
| 157 | // next => "" / ( 1*( OWS "," ) [ OWS element ] ) | ||
| 158 | |||
| 159 | // "" | ||
| 160 | 9274x | if(it == end) | |
| 161 | 9189x | return grammar::error::end_of_range; | |
| 162 | |||
| 163 | // 1*( OWS "," ) | ||
| 164 | { | ||
| 165 | 85x | auto it0 = it; | |
| 166 | 85x | detail::ows_comma.parse(it, end); | |
| 167 | 85x | if(it == it0) | |
| 168 | 8x | return grammar::error::end_of_range; | |
| 169 | } | ||
| 170 | 77x | auto it1 = it; | |
| 171 | // OWS | ||
| 172 | 77x | it = grammar::find_if_not( | |
| 173 | it, end, detail::ws); | ||
| 174 | 77x | auto rv = this->get().parse(it, end); | |
| 175 | 77x | if(rv) | |
| 176 | 68x | return std::move(*rv); | |
| 177 | 9x | it = it1; | |
| 178 | 9x | return grammar::error::end_of_range; | |
| 179 | 25x | } | |
| 180 | }; | ||
| 181 | |||
| 182 | template<class Rule> | ||
| 183 | auto | ||
| 184 | 4659x | list_rule_t<Rule>:: | |
| 185 | parse( | ||
| 186 | char const*& it, | ||
| 187 | char const* end) const -> | ||
| 188 | system::result<value_type> | ||
| 189 | { | ||
| 190 | return grammar::parse(it, end, | ||
| 191 | 9318x | grammar::range_rule( | |
| 192 | first_rule{this->get()}, | ||
| 193 | next_rule{this->get()}, | ||
| 194 | 13977x | n_, m_)); | |
| 195 | } | ||
| 196 | } // implementation_defined | ||
| 197 | |||
| 198 | } // http | ||
| 199 | } // boost | ||
| 200 | |||
| 201 | #endif | ||
| 202 |