![]() |
|
|||
File indexing completed on 2025-09-18 09:07:55
0001 // 0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) 0003 // 0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying 0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0006 // 0007 // Official repository: https://github.com/boostorg/url 0008 // 0009 0010 #ifndef BOOST_URL_GRAMMAR_VARIANT_RULE_HPP 0011 #define BOOST_URL_GRAMMAR_VARIANT_RULE_HPP 0012 0013 #include <boost/url/detail/config.hpp> 0014 #include <boost/url/error_types.hpp> 0015 #include <boost/url/variant.hpp> 0016 #include <boost/url/grammar/detail/tuple.hpp> 0017 #include <boost/url/grammar/type_traits.hpp> 0018 0019 namespace boost { 0020 namespace urls { 0021 namespace grammar { 0022 0023 namespace implementation_defined { 0024 template< 0025 class R0, class... Rn> 0026 class variant_rule_t 0027 { 0028 public: 0029 using value_type = variant2::variant< 0030 typename R0::value_type, 0031 typename Rn::value_type...>; 0032 0033 auto 0034 parse( 0035 char const*& it, 0036 char const* end) const -> 0037 system::result<value_type>; 0038 0039 constexpr 0040 variant_rule_t( 0041 R0 const& r0, 0042 Rn const&... rn) noexcept 0043 : rn_(r0, rn...) 0044 { 0045 } 0046 0047 private: 0048 0049 detail::tuple<R0, Rn...> rn_; 0050 }; 0051 } // implementation_defined 0052 0053 /** Match one of a set of rules 0054 0055 Each specified rule is tried in sequence. 0056 When the first match occurs, the result 0057 is stored and returned in the variant. If 0058 no match occurs, an error is returned. 0059 0060 @param r0 The first rule to match 0061 @param rn A list of one or more rules to match 0062 @return The variant rule 0063 0064 @par Value Type 0065 @code 0066 using value_type = variant< typename Rules::value_type... >; 0067 @endcode 0068 0069 @par Example 0070 Rules are used with the function @ref parse. 0071 @code 0072 // request-target = origin-form 0073 // / absolute-form 0074 // / authority-form 0075 // / asterisk-form 0076 0077 system::result< variant< url_view, url_view, authority_view, core::string_view > > rv = grammar::parse( 0078 "/index.html?width=full", 0079 variant_rule( 0080 origin_form_rule, 0081 absolute_uri_rule, 0082 authority_rule, 0083 delim_rule('*') ) ); 0084 @endcode 0085 0086 @par BNF 0087 @code 0088 variant = rule1 / rule2 / rule3... 0089 @endcode 0090 0091 @par Specification 0092 @li <a href="https://datatracker.ietf.org/doc/html/rfc5234#section-3.2" 0093 >3.2. Alternatives (rfc5234)</a> 0094 @li <a href="https://datatracker.ietf.org/doc/html/rfc7230#section-5.3" 0095 >5.3. Request Target (rfc7230)</a> 0096 0097 @see 0098 @ref absolute_uri_rule, 0099 @ref authority_rule, 0100 @ref delim_rule, 0101 @ref parse, 0102 @ref origin_form_rule, 0103 @ref url_view. 0104 */ 0105 template< 0106 BOOST_URL_CONSTRAINT(Rule) R0, 0107 BOOST_URL_CONSTRAINT(Rule)... Rn> 0108 constexpr 0109 auto 0110 variant_rule( 0111 R0 const& r0, 0112 Rn const&... rn) noexcept -> 0113 implementation_defined::variant_rule_t<R0, Rn...>; 0114 0115 } // grammar 0116 } // urls 0117 } // boost 0118 0119 #include <boost/url/grammar/impl/variant_rule.hpp> 0120 0121 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |