LCOV - code coverage report
Current view: top level - /jenkins/workspace/boost-root/libs/url/src - decode_view.cpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 100.0 % 96 96
Test Date: 2026-03-02 22:26:03 Functions: 100.0 % 10 10

           TLA  Line data    Source code
       1                 : //
       2                 : // Copyright (c) 2022 Alan de Freitas (alandefreitas@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/boostorg/url
       8                 : //
       9                 : 
      10                 : 
      11                 : #include <boost/url/detail/config.hpp>
      12                 : #include <boost/url/decode_view.hpp>
      13                 : #include <boost/url/grammar/hexdig_chars.hpp>
      14                 : #include <ostream>
      15                 : 
      16                 : namespace boost {
      17                 : namespace urls {
      18                 : 
      19                 : //------------------------------------------------
      20                 : 
      21                 : auto
      22 HIT     1181712 : decode_view::
      23                 : iterator::
      24                 : operator*() const noexcept ->
      25                 :     reference
      26                 : {
      27         1181712 :     if (space_as_plus_ &&
      28              73 :         *pos_ == '+')
      29               8 :         return ' ';
      30         1181704 :     if (*pos_ != '%')
      31          958035 :         return *pos_;
      32          223669 :     auto d0 = grammar::hexdig_value(pos_[1]);
      33          223669 :     auto d1 = grammar::hexdig_value(pos_[2]);
      34                 :     return static_cast<char>(
      35          223669 :         ((static_cast<
      36          223669 :               unsigned char>(d0) << 4) +
      37          223669 :          (static_cast<
      38          223669 :              unsigned char>(d1))));
      39                 : }
      40                 : 
      41                 : void
      42              21 : decode_view::
      43                 : write(std::ostream& os) const
      44                 : {
      45              21 :     auto it = begin();
      46              21 :     auto const end_ = end();
      47             226 :     while(it != end_)
      48             205 :         os.put(*it++);
      49              21 : }
      50                 : 
      51                 : void
      52               4 : decode_view::
      53                 : remove_prefix( size_type n )
      54                 : {
      55               4 :     BOOST_ASSERT(n <= dn_);
      56               4 :     auto it = begin();
      57               4 :     auto n0 = n;
      58              24 :     while (n)
      59                 :     {
      60              20 :         ++it;
      61              20 :         --n;
      62                 :     }
      63               4 :     n_ -= (it.base() - begin().base());
      64               4 :     dn_ -= n0;
      65               4 :     p_ = it.base();
      66               4 : }
      67                 : 
      68                 : void
      69               4 : decode_view::
      70                 : remove_suffix( size_type n )
      71                 : {
      72               4 :     BOOST_ASSERT(n <= dn_);
      73               4 :     auto it = end();
      74               4 :     auto n0 = n;
      75              25 :     while (n)
      76                 :     {
      77              21 :         --it;
      78              21 :         --n;
      79                 :     }
      80               4 :     n_ -= (end().base() - it.base());
      81               4 :     dn_ -= n0;
      82               4 : }
      83                 : 
      84                 : bool
      85               4 : decode_view::
      86                 : starts_with( core::string_view s ) const noexcept
      87                 : {
      88               4 :     if (s.size() > size())
      89               1 :         return false;
      90               3 :     auto it0 = begin();
      91               3 :     auto it1 = s.begin();
      92               3 :     std::size_t n = s.size();
      93              19 :     while (n)
      94                 :     {
      95              17 :         if (*it0 != *it1)
      96               1 :             return false;
      97              16 :         ++it0;
      98              16 :         ++it1;
      99              16 :         --n;
     100                 :     }
     101               2 :     return true;
     102                 : }
     103                 : 
     104                 : bool
     105               6 : decode_view::
     106                 : ends_with( core::string_view s ) const noexcept
     107                 : {
     108               6 :     if (s.empty())
     109               2 :         return true;
     110               4 :     if (s.size() > size())
     111               1 :         return false;
     112               3 :     auto it0 = end();
     113               3 :     auto it1 = s.end();
     114               3 :     std::size_t n = s.size();
     115               3 :     --it0;
     116               3 :     --it1;
     117              19 :     while (n - 1)
     118                 :     {
     119              17 :         if (*it0 != *it1)
     120               1 :             return false;
     121              16 :         --it0;
     122              16 :         --it1;
     123              16 :         --n;
     124                 :     }
     125               2 :     return *it0 == *it1;
     126                 : }
     127                 : 
     128                 : bool
     129               2 : decode_view::
     130                 : starts_with( char ch ) const noexcept
     131                 : {
     132                 :     return
     133               4 :         !empty() &&
     134               4 :         front() == ch;
     135                 : }
     136                 : 
     137                 : bool
     138               2 : decode_view::
     139                 : ends_with( char ch ) const noexcept
     140                 : {
     141                 :     return
     142               4 :         !empty() &&
     143               4 :         back() == ch;
     144                 : }
     145                 : 
     146                 : decode_view::const_iterator
     147               2 : decode_view::
     148                 : find( char ch ) const noexcept
     149                 : {
     150               2 :     auto it = begin();
     151               2 :     auto end = this->end();
     152               8 :     while (it != end)
     153                 :     {
     154               7 :         if (*it == ch)
     155               1 :             return it;
     156               6 :         ++it;
     157                 :     }
     158               1 :     return it;
     159                 : }
     160                 : 
     161                 : decode_view::const_iterator
     162               5 : decode_view::
     163                 : rfind( char ch ) const noexcept
     164                 : {
     165               5 :     if (empty())
     166               1 :         return end();
     167               4 :     auto it = end();
     168               4 :     auto begin = this->begin();
     169               4 :     --it;
     170              27 :     while (it != begin)
     171                 :     {
     172              25 :         if (*it == ch)
     173               2 :             return it;
     174              23 :         --it;
     175                 :     }
     176               2 :     if (*it == ch)
     177               1 :         return it;
     178               1 :     return end();
     179                 : }
     180                 : 
     181                 : } // urls
     182                 : } // boost
     183                 : 
        

Generated by: LCOV version 2.3