LCOV - code coverage report
Current view: top level - url/grammar - literal_rule.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 8 8
Test Date: 2026-02-13 15:53:22 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              : // 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/url
       9              : //
      10              : 
      11              : #ifndef BOOST_URL_GRAMMAR_LITERAL_RULE_HPP
      12              : #define BOOST_URL_GRAMMAR_LITERAL_RULE_HPP
      13              : 
      14              : #include <boost/url/detail/config.hpp>
      15              : #include <boost/url/error_types.hpp>
      16              : #include <boost/core/detail/string_view.hpp>
      17              : #include <cstdlib>
      18              : 
      19              : namespace boost {
      20              : namespace urls {
      21              : namespace grammar {
      22              : 
      23              : /** Match a string literal exactly
      24              : 
      25              :     If there is no more input, or if the
      26              :     end of the input is reached, and a prefix
      27              :     of the literal matches exactly, the error
      28              :     returned is @ref error::need_more.
      29              : 
      30              :     @par Value Type
      31              :     @code
      32              :     using value_type = core::string_view;
      33              :     @endcode
      34              : 
      35              :     @par Example
      36              :     Rules are used with the function @ref parse.
      37              :     @code
      38              :     system::result< core::string_view > rv = parse( "HTTP", literal_rule( "HTTP" ) );
      39              :     @endcode
      40              : 
      41              :     @see
      42              :         @ref delim_rule,
      43              :         @ref parse.
      44              : */
      45              : class literal_rule
      46              : {
      47              :     char const* s_ = nullptr;
      48              :     std::size_t n_ = 0;
      49              : 
      50              :     constexpr
      51              :     static
      52              :     std::size_t
      53           48 :     len(char const* s) noexcept
      54              :     {
      55           48 :         return *s
      56           48 :             ? 1 + len(s + 1)
      57           48 :             : 0;
      58              :     }
      59              : 
      60              : public:
      61              :     using value_type = core::string_view;
      62              : 
      63              :     constexpr
      64              :     explicit
      65           10 :     literal_rule(
      66              :         char const* s) noexcept
      67           10 :         : s_(s)
      68           10 :         , n_(len(s))
      69              :     {
      70           10 :     }
      71              : 
      72              :     BOOST_URL_CXX20_CONSTEXPR
      73              :     system::result<value_type>
      74              :     parse(
      75              :         char const*& it,
      76              :         char const* end) const noexcept;
      77              : };
      78              : 
      79              : } // grammar
      80              : } // urls
      81              : } // boost
      82              : 
      83              : #include <boost/url/grammar/impl/literal_rule.hpp>
      84              : 
      85              : #endif
        

Generated by: LCOV version 2.3