Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2016-2019 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/boostorg/url |
8 |
|
|
// |
9 |
|
|
|
10 |
|
|
#ifndef BOOST_URL_GRAMMAR_VARIANT_RULE_HPP |
11 |
|
|
#define BOOST_URL_GRAMMAR_VARIANT_RULE_HPP |
12 |
|
|
|
13 |
|
|
#include <boost/url/detail/config.hpp> |
14 |
|
|
#include <boost/url/error_types.hpp> |
15 |
|
|
#include <boost/url/variant.hpp> |
16 |
|
|
#include <boost/url/grammar/detail/tuple.hpp> |
17 |
|
|
|
18 |
|
|
namespace boost { |
19 |
|
|
namespace urls { |
20 |
|
|
namespace grammar { |
21 |
|
|
|
22 |
|
|
/** Match one of a set of rules |
23 |
|
|
|
24 |
|
|
Each specified rule is tried in sequence. |
25 |
|
|
When the first match occurs, the result |
26 |
|
|
is stored and returned in the variant. If |
27 |
|
|
no match occurs, an error is returned. |
28 |
|
|
|
29 |
|
|
@par Value Type |
30 |
|
|
@code |
31 |
|
|
using value_type = variant< typename Rules::value_type... >; |
32 |
|
|
@endcode |
33 |
|
|
|
34 |
|
|
@par Example |
35 |
|
|
Rules are used with the function @ref parse. |
36 |
|
|
@code |
37 |
|
|
// request-target = origin-form |
38 |
|
|
// / absolute-form |
39 |
|
|
// / authority-form |
40 |
|
|
// / asterisk-form |
41 |
|
|
|
42 |
|
|
system::result< variant< url_view, url_view, authority_view, core::string_view > > rv = grammar::parse( |
43 |
|
|
"/index.html?width=full", |
44 |
|
|
variant_rule( |
45 |
|
|
origin_form_rule, |
46 |
|
|
absolute_uri_rule, |
47 |
|
|
authority_rule, |
48 |
|
|
delim_rule('*') ) ); |
49 |
|
|
@endcode |
50 |
|
|
|
51 |
|
|
@par BNF |
52 |
|
|
@code |
53 |
|
|
variant = rule1 / rule2 / rule3... |
54 |
|
|
@endcode |
55 |
|
|
|
56 |
|
|
@par Specification |
57 |
|
|
@li <a href="https://datatracker.ietf.org/doc/html/rfc5234#section-3.2" |
58 |
|
|
>3.2. Alternatives (rfc5234)</a> |
59 |
|
|
@li <a href="https://datatracker.ietf.org/doc/html/rfc7230#section-5.3" |
60 |
|
|
>5.3. Request Target (rfc7230)</a> |
61 |
|
|
|
62 |
|
|
@see |
63 |
|
|
@ref absolute_uri_rule, |
64 |
|
|
@ref authority_rule, |
65 |
|
|
@ref delim_rule, |
66 |
|
|
@ref parse, |
67 |
|
|
@ref origin_form_rule, |
68 |
|
|
@ref url_view. |
69 |
|
|
*/ |
70 |
|
|
#ifdef BOOST_URL_DOCS |
71 |
|
|
template<class... Rules> |
72 |
|
|
constexpr |
73 |
|
|
__implementation_defined__ |
74 |
|
|
variant_rule( Rules... rn ) noexcept; |
75 |
|
|
#else |
76 |
|
|
template< |
77 |
|
|
class R0, class... Rn> |
78 |
|
|
class variant_rule_t |
79 |
|
|
{ |
80 |
|
|
public: |
81 |
|
|
using value_type = variant< |
82 |
|
|
typename R0::value_type, |
83 |
|
|
typename Rn::value_type...>; |
84 |
|
|
|
85 |
|
|
auto |
86 |
|
|
parse( |
87 |
|
|
char const*& it, |
88 |
|
|
char const* end) const -> |
89 |
|
|
system::result<value_type>; |
90 |
|
|
|
91 |
|
|
template< |
92 |
|
|
class R0_, |
93 |
|
|
class... Rn_> |
94 |
|
|
friend |
95 |
|
|
constexpr |
96 |
|
|
auto |
97 |
|
|
variant_rule( |
98 |
|
|
R0_ const& r0, |
99 |
|
|
Rn_ const&... rn) noexcept -> |
100 |
|
|
variant_rule_t<R0_, Rn_...>; |
101 |
|
|
|
102 |
|
|
private: |
103 |
|
|
constexpr |
104 |
|
2470 |
variant_rule_t( |
105 |
|
|
R0 const& r0, |
106 |
|
|
Rn const&... rn) noexcept |
107 |
|
2470 |
: rn_(r0, rn...) |
108 |
|
|
{ |
109 |
|
2470 |
} |
110 |
|
|
|
111 |
|
|
detail::tuple<R0, Rn...> rn_; |
112 |
|
|
}; |
113 |
|
|
|
114 |
|
|
template< |
115 |
|
|
class R0, |
116 |
|
|
class... Rn> |
117 |
|
|
constexpr |
118 |
|
|
auto |
119 |
|
|
variant_rule( |
120 |
|
|
R0 const& r0, |
121 |
|
|
Rn const&... rn) noexcept -> |
122 |
|
|
variant_rule_t<R0, Rn...>; |
123 |
|
|
#endif |
124 |
|
|
|
125 |
|
|
} // grammar |
126 |
|
|
} // urls |
127 |
|
|
} // boost |
128 |
|
|
|
129 |
|
|
#include <boost/url/grammar/impl/variant_rule.hpp> |
130 |
|
|
|
131 |
|
|
#endif |
132 |
|
|
|