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