LCOV - code coverage report
Current view: top level - boost/url/grammar/variant_rule.hpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 3 3
Test Date: 2024-08-20 16:05:53 Functions: 100.0 % 2 2

            Line data    Source code
       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              : namespace implementation_defined {
      77              : template<
      78              :     class R0, class... Rn>
      79              : class variant_rule_t
      80              : {
      81              : public:
      82              :     using value_type = variant2::variant<
      83              :         typename R0::value_type,
      84              :         typename Rn::value_type...>;
      85              : 
      86              :     auto
      87              :     parse(
      88              :         char const*& it,
      89              :         char const* end) const ->
      90              :             system::result<value_type>;
      91              : 
      92              :     constexpr
      93         2495 :     variant_rule_t(
      94              :         R0 const& r0,
      95              :         Rn const&... rn) noexcept
      96         2495 :         : rn_(r0, rn...)
      97              :     {
      98         2495 :     }
      99              : 
     100              : private:
     101              : 
     102              :     detail::tuple<R0, Rn...> rn_;
     103              : };
     104              : } // implementation_defined
     105              : 
     106              : /** Match one of a set of rules
     107              : 
     108              :     Each specified rule is tried in sequence.
     109              :     When the first match occurs, the result
     110              :     is stored and returned in the variant. If
     111              :     no match occurs, an error is returned.
     112              : 
     113              :     @par Value Type
     114              :     @code
     115              :     using value_type = variant< typename Rules::value_type... >;
     116              :     @endcode
     117              : 
     118              :     @par Example
     119              :     Rules are used with the function @ref parse.
     120              :     @code
     121              :     // request-target = origin-form
     122              :     //                / absolute-form
     123              :     //                / authority-form
     124              :     //                / asterisk-form
     125              : 
     126              :     system::result< variant< url_view, url_view, authority_view, core::string_view > > rv = grammar::parse(
     127              :         "/index.html?width=full",
     128              :         variant_rule(
     129              :             origin_form_rule,
     130              :             absolute_uri_rule,
     131              :             authority_rule,
     132              :             delim_rule('*') ) );
     133              :     @endcode
     134              : 
     135              :     @par BNF
     136              :     @code
     137              :     variant     = rule1 / rule2 / rule3...
     138              :     @endcode
     139              : 
     140              :     @par Specification
     141              :     @li <a href="https://datatracker.ietf.org/doc/html/rfc5234#section-3.2"
     142              :         >3.2.  Alternatives (rfc5234)</a>
     143              :     @li <a href="https://datatracker.ietf.org/doc/html/rfc7230#section-5.3"
     144              :         >5.3.  Request Target (rfc7230)</a>
     145              : 
     146              :     @see
     147              :         @ref absolute_uri_rule,
     148              :         @ref authority_rule,
     149              :         @ref delim_rule,
     150              :         @ref parse,
     151              :         @ref origin_form_rule,
     152              :         @ref url_view.
     153              : */
     154              : template<
     155              :     class R0,
     156              :     class... Rn>
     157              : constexpr
     158              : auto
     159              : variant_rule(
     160              :     R0 const& r0,
     161              :     Rn const&... rn) noexcept ->
     162              :         implementation_defined::variant_rule_t<R0, Rn...>;
     163              : #endif
     164              : 
     165              : } // grammar
     166              : } // urls
     167              : } // boost
     168              : 
     169              : #include <boost/url/grammar/impl/variant_rule.hpp>
     170              : 
     171              : #endif
        

Generated by: LCOV version 2.1