LCOV - code coverage report
Current view: top level - url/grammar - token_rule.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 5 5
Test Date: 2026-02-13 15:53:22 Functions: 100.0 % 15 15

            Line data    Source code
       1              : //
       2              : // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
       3              : // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
       4              : //
       5              : // Distributed under the Boost Software License, Version 1.0. (See accompanying
       6              : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
       7              : //
       8              : // Official repository: https://github.com/boostorg/http_proto
       9              : //
      10              : 
      11              : #ifndef BOOST_URL_GRAMMAR_TOKEN_RULE_HPP
      12              : #define BOOST_URL_GRAMMAR_TOKEN_RULE_HPP
      13              : 
      14              : #include <boost/url/detail/config.hpp>
      15              : #include <boost/url/grammar/charset.hpp>
      16              : #include <boost/url/error_types.hpp>
      17              : #include <boost/core/detail/string_view.hpp>
      18              : #include <boost/core/empty_value.hpp>
      19              : #include <type_traits>
      20              : 
      21              : namespace boost {
      22              : namespace urls {
      23              : namespace grammar {
      24              : 
      25              : namespace implementation_defined {
      26              : template<class CharSet>
      27              : struct token_rule_t
      28              :     : private empty_value<CharSet>
      29              : {
      30              :     using value_type = core::string_view;
      31              : 
      32              :     static_assert(
      33              :         is_charset<CharSet>::value,
      34              :         "CharSet requirements not met");
      35              : 
      36              :     BOOST_URL_CXX14_CONSTEXPR
      37              :     auto
      38              :     parse(
      39              :         char const*& it,
      40              :         char const* end
      41              :             ) const noexcept ->
      42              :         system::result<value_type>;
      43              : 
      44              :     constexpr
      45           79 :     token_rule_t(
      46              :         CharSet const& cs) noexcept
      47              :         : empty_value<CharSet>(
      48           79 :             empty_init, cs)
      49              :     {
      50           79 :     }
      51              : 
      52              :     template<class CS = CharSet>
      53              :     constexpr
      54              :     token_rule_t(
      55              :         typename std::enable_if<
      56              :             std::is_default_constructible<CS>::value,
      57              :             int>::type = 0) noexcept
      58              :         : empty_value<CharSet>(
      59              :             empty_init)
      60              :     {
      61              :     }
      62              : };
      63              : }
      64              : 
      65              : /** Match a non-empty string of characters from a set
      66              : 
      67              :     If there is no more input, the error code
      68              :     @ref error::need_more is returned.
      69              : 
      70              :     @par Value Type
      71              :     @code
      72              :     using value_type = core::string_view;
      73              :     @endcode
      74              : 
      75              :     @par Example
      76              :     Rules are used with the function @ref parse.
      77              :     @code
      78              :     system::result< core::string_view > rv = parse( "abcdef", token_rule( alpha_chars ) );
      79              :     @endcode
      80              : 
      81              :     @par BNF
      82              :     @code
      83              :     token     = 1*( ch )
      84              :     @endcode
      85              : 
      86              :     @param cs The character set to use
      87              :     @return The token rule
      88              : 
      89              :     @see
      90              :         @ref alpha_chars,
      91              :         @ref parse.
      92              : */
      93              : template<BOOST_URL_CONSTRAINT(CharSet) CS>
      94              : constexpr
      95              : auto
      96           79 : token_rule(
      97              :     CS const& cs) noexcept ->
      98              :         implementation_defined::token_rule_t<CS>
      99              : {
     100           79 :     return {cs};
     101              : }
     102              : 
     103              : /** Match a non-empty string of characters from a default-constructible set
     104              : 
     105              :     This overload is only available when CharSet is
     106              :     default constructible.
     107              : 
     108              :     If there is no more input, the error code
     109              :     @ref error::need_more is returned.
     110              : 
     111              :     @par Value Type
     112              :     @code
     113              :     using value_type = core::string_view;
     114              :     @endcode
     115              : 
     116              :     @par Example
     117              :     Rules are used with the function @ref parse.
     118              :     @code
     119              :     system::result< core::string_view > rv = parse( "abcdef", token_rule<alpha_chars_t>() );
     120              :     @endcode
     121              : 
     122              :     @par BNF
     123              :     @code
     124              :     token     = 1*( ch )
     125              :     @endcode
     126              : 
     127              :     @tparam CharSet The character set type to use
     128              :     @return The token rule
     129              : 
     130              :     @see
     131              :         @ref alpha_chars,
     132              :         @ref parse.
     133              : */
     134              : template<BOOST_URL_CONSTRAINT(CharSet) CharSet>
     135              : constexpr
     136              : auto
     137              : token_rule() noexcept ->
     138              :     typename std::enable_if<
     139              :         std::is_default_constructible<CharSet>::value,
     140              :         implementation_defined::token_rule_t<CharSet>>::type
     141              : {
     142              :     return implementation_defined::token_rule_t<CharSet>();
     143              : }
     144              : 
     145              : } // grammar
     146              : } // urls
     147              : } // boost
     148              : 
     149              : #include <boost/url/grammar/impl/token_rule.hpp>
     150              : 
     151              : #endif
        

Generated by: LCOV version 2.3