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

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

Generated by: LCOV version 2.1