LCOV - code coverage report
Current view: top level - url/rfc - pct_encoded_rule.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 5 5
Test Date: 2026-02-25 21:00:01 Functions: 100.0 % 5 5

           TLA  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_RFC_PCT_ENCODED_RULE_HPP
      12                 : #define BOOST_URL_RFC_PCT_ENCODED_RULE_HPP
      13                 : 
      14                 : #include <boost/url/detail/config.hpp>
      15                 : #include <boost/url/error_types.hpp>
      16                 : #include <boost/url/pct_string_view.hpp>
      17                 : #include <boost/url/grammar/charset.hpp>
      18                 : 
      19                 : namespace boost {
      20                 : namespace urls {
      21                 : namespace implementation_defined {
      22                 : template<class CharSet>
      23                 : struct pct_encoded_rule_t
      24                 : {
      25                 :     using value_type = pct_string_view;
      26                 : 
      27                 :     BOOST_URL_CXX20_CONSTEXPR
      28                 :     system::result<value_type>
      29                 :     parse(
      30                 :         char const*& it,
      31                 :         char const* end) const noexcept;
      32                 : 
      33                 :     constexpr
      34 HIT        3532 :     pct_encoded_rule_t(
      35                 :         CharSet const& cs) noexcept
      36            3532 :         : cs_(cs)
      37                 :     {
      38            3532 :     }
      39                 : 
      40                 : private:
      41                 :     CharSet cs_;
      42                 : };
      43                 : } // implementation_defined
      44                 : 
      45                 : /** Rule for a string with percent-encoded escapes
      46                 : 
      47                 :     This function returns a rule which matches
      48                 :     a percent-encoded string, permitting characters
      49                 :     in the string which are also in the specified
      50                 :     character set to be used unescaped.
      51                 : 
      52                 :     @par Value Type
      53                 :     @code
      54                 :     using value_type = pct_string_view;
      55                 :     @endcode
      56                 : 
      57                 :     @par Example
      58                 :     Rules are used with the function @ref grammar::parse.
      59                 :     @code
      60                 :     //  pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
      61                 : 
      62                 :     system::result< pct_string_view > rv = grammar::parse( "Program%20Files", pct_encoded_rule( pchars ) );
      63                 :     @endcode
      64                 : 
      65                 :     @par BNF
      66                 :     @code
      67                 :     pct-encoded   = "%" HEXDIG HEXDIG
      68                 :     @endcode
      69                 : 
      70                 :     @param cs The character set indicating
      71                 :     which characters are allowed without escapes.
      72                 :     Any character which is not in this set must be
      73                 :     escaped, or else parsing returns an error.
      74                 : 
      75                 :     @return A rule object.
      76                 : 
      77                 :     @par Specification
      78                 :     @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-2.1">
      79                 :         2.1. Percent-Encoding (rfc3986)</a>
      80                 : 
      81                 :     @see
      82                 :         @ref grammar::parse,
      83                 :         @ref pchars,
      84                 :         @ref pct_string_view.
      85                 : */
      86                 : template<BOOST_URL_CONSTRAINT(grammar::CharSet) CS>
      87                 : constexpr
      88                 : auto
      89            3532 : pct_encoded_rule(CS const& cs) noexcept ->
      90                 :     implementation_defined::pct_encoded_rule_t<CS>
      91                 : {
      92                 :     // If an error occurs here it means that
      93                 :     // the value of your type does not meet
      94                 :     // the requirements. Please check the
      95                 :     // documentation!
      96                 :     static_assert(
      97                 :         grammar::is_charset<CS>::value,
      98                 :         "CharSet requirements not met");
      99                 : 
     100            3532 :     return implementation_defined::pct_encoded_rule_t<CS>(cs);
     101                 : }
     102                 : 
     103                 : } // urls
     104                 : } // boost
     105                 : 
     106                 : #include <boost/url/rfc/impl/pct_encoded_rule.hpp>
     107                 : 
     108                 : #endif
        

Generated by: LCOV version 2.3