LCOV - code coverage report
Current view: top level - boost/url/grammar - optional_rule.hpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 5 5 100.0 %
Date: 2024-03-13 19:32:03 Functions: 10 10 100.0 %

          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_OPTIONAL_RULE_HPP
      11             : #define BOOST_URL_GRAMMAR_OPTIONAL_RULE_HPP
      12             : 
      13             : #include <boost/url/detail/config.hpp>
      14             : #include <boost/url/optional.hpp>
      15             : #include <boost/url/error_types.hpp>
      16             : #include <boost/core/empty_value.hpp>
      17             : #include <boost/assert.hpp>
      18             : 
      19             : namespace boost {
      20             : namespace urls {
      21             : namespace grammar {
      22             : 
      23             : /** Match a rule, or the empty string
      24             : 
      25             :     Optional BNF elements are denoted with
      26             :     square brackets. If the specified rule
      27             :     returns any error it is treated as if
      28             :     the rule did not match.
      29             : 
      30             :     @par Value Type
      31             :     @code
      32             :     using value_type = optional< typename Rule::value_type >;
      33             :     @endcode
      34             : 
      35             :     @par Example
      36             :     Rules are used with the function @ref grammar::parse.
      37             :     @code
      38             :     system::result< optional< core::string_view > > rv = parse( "", optional_rule( token_rule( alpha_chars ) ) );
      39             :     @endcode
      40             : 
      41             :     @par BNF
      42             :     @code
      43             :     optional     = [ rule ]
      44             :     @endcode
      45             : 
      46             :     @par Specification
      47             :     @li <a href="https://datatracker.ietf.org/doc/html/rfc5234#section-3.8"
      48             :         >3.8.  Optional Sequence (rfc5234)</a>
      49             : 
      50             :     @param r The rule to match
      51             : 
      52             :     @see
      53             :         @ref alpha_chars,
      54             :         @ref parse,
      55             :         @ref optional,
      56             :         @ref token_rule.
      57             : */
      58             : #ifdef BOOST_URL_DOCS
      59             : template<class Rule>
      60             : constexpr
      61             : __implementation_defined__
      62             : optional_rule( Rule r ) noexcept;
      63             : #else
      64             : template<class Rule>
      65             : struct optional_rule_t
      66             :     : private empty_value<Rule>
      67             : {
      68             :     using value_type = boost::optional<
      69             :         typename Rule::value_type>;
      70             : 
      71             :     system::result<value_type>
      72             :     parse(
      73             :         char const*& it,
      74             :         char const* end) const;
      75             : 
      76             :     template<class R_>
      77             :     friend
      78             :     constexpr
      79             :     auto
      80             :     optional_rule(
      81             :         R_ const& r) ->
      82             :             optional_rule_t<R_>;
      83             : 
      84             : private:
      85             :     constexpr
      86        1958 :     optional_rule_t(
      87             :         Rule const& r) noexcept
      88             :         : empty_value<Rule>(
      89             :             empty_init,
      90        1958 :             r)
      91             :     {
      92        1958 :     }
      93             : };
      94             : 
      95             : template<class Rule>
      96             : auto
      97             : constexpr
      98        1958 : optional_rule(
      99             :     Rule const& r) ->
     100             :         optional_rule_t<Rule>
     101             : {
     102        1958 :     return { r };
     103             : }
     104             : #endif
     105             : 
     106             : } // grammar
     107             : } // urls
     108             : } // boost
     109             : 
     110             : #include <boost/url/grammar/impl/optional_rule.hpp>
     111             : 
     112             : #endif

Generated by: LCOV version 1.15