LCOV - code coverage report
Current view: top level - include/boost/http/rfc - quoted_token_view.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 12 12
Test Date: 2026-06-13 19:44:58 Functions: 100.0 % 2 2

           TLA  Line data    Source code
       1                 : //
       2                 : // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.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/cppalliance/http
       8                 : //
       9                 : 
      10                 : #ifndef BOOST_HTTP_RFC_QUOTED_TOKEN_VIEW_HPP
      11                 : #define BOOST_HTTP_RFC_QUOTED_TOKEN_VIEW_HPP
      12                 : 
      13                 : #include <boost/http/detail/config.hpp>
      14                 : #include <boost/url/grammar/string_view_base.hpp>
      15                 : #include <boost/core/detail/string_view.hpp>
      16                 : 
      17                 : namespace boost {
      18                 : namespace http {
      19                 : 
      20                 : namespace implementation_defined {
      21                 : struct quoted_token_rule_t;
      22                 : } // implementation_defined
      23                 : 
      24                 : /** A view into a quoted string token, which may
      25                 :     contain escape sequences.
      26                 : 
      27                 :     @see
      28                 :         @ref quoted_token_view.
      29                 : */
      30                 : class quoted_token_view final
      31                 :     : public grammar::string_view_base
      32                 : {
      33                 :     std::size_t n_ = 0;
      34                 : 
      35                 :     friend struct implementation_defined::quoted_token_rule_t;
      36                 : 
      37                 :     // unquoted
      38                 :     explicit
      39 HIT          15 :     quoted_token_view(
      40                 :         core::string_view s) noexcept
      41              15 :         : string_view_base(s)
      42              15 :         , n_(s.size())
      43                 :     {
      44              15 :     }
      45                 : 
      46                 :     // maybe quoted
      47               6 :     quoted_token_view(
      48                 :         core::string_view s,
      49                 :         std::size_t n) noexcept
      50               6 :         : string_view_base(s)
      51               6 :         , n_(n)
      52                 :     {
      53               6 :         BOOST_ASSERT(s.size() >= 2);
      54               6 :         BOOST_ASSERT(s.front() == '\"');
      55               6 :         BOOST_ASSERT(s.back() == '\"');
      56               6 :         BOOST_ASSERT(n_ <= s_.size() - 2);
      57               6 :     }
      58                 : 
      59                 : public:
      60                 :     quoted_token_view() = default;
      61                 : 
      62                 :     quoted_token_view(
      63                 :         quoted_token_view const&) noexcept = default;
      64                 : 
      65                 :     quoted_token_view& operator=(
      66                 :         quoted_token_view const&) noexcept = default;
      67                 : 
      68                 :     /** Return true if the token contains escape
      69                 :         sequences.
      70                 : 
      71                 :         @par Complexity
      72                 :         Constant.
      73                 : 
      74                 :         @Return true if the token contains
      75                 :         escape sequences.
      76                 :     */
      77                 :     bool
      78                 :     has_escapes() const noexcept
      79                 :     {
      80                 :         return n_ != s_.size();
      81                 :     }
      82                 : 
      83                 :     /** Return the size of the unescaped content.
      84                 : 
      85                 :         @par Complexity
      86                 :         Constant.
      87                 : 
      88                 :          @return Size of the unescaped string content.
      89                 :     */
      90                 :     std::size_t
      91                 :     unescaped_size() const noexcept
      92                 :     {
      93                 :         return n_;
      94                 :     }
      95                 : };
      96                 : 
      97                 : } // http
      98                 : } // boost
      99                 : 
     100                 : #endif
        

Generated by: LCOV version 2.3