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