100.00% Lines (33/33) 100.00% Functions (3/3)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2022 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2022 Vinnie Falco (vinnie.falco@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/error.hpp> 12   #include <boost/url/error.hpp>
13   #include <boost/url/pct_string_view.hpp> 13   #include <boost/url/pct_string_view.hpp>
14   #include <boost/url/detail/decode.hpp> 14   #include <boost/url/detail/decode.hpp>
15   #include <boost/url/grammar/hexdig_chars.hpp> 15   #include <boost/url/grammar/hexdig_chars.hpp>
16   #include <boost/url/detail/except.hpp> 16   #include <boost/url/detail/except.hpp>
17   17  
18   namespace boost { 18   namespace boost {
19   namespace urls { 19   namespace urls {
20   20  
21   void 21   void
HITCBC 22   21044 pct_string_view:: 22   21044 pct_string_view::
23   decode_impl( 23   decode_impl(
24   string_token::arg& dest, 24   string_token::arg& dest,
25   encoding_opts opt) const 25   encoding_opts opt) const
26   { 26   {
HITCBC 27   21044 auto p = dest.prepare(dn_); 27   21044 auto p = dest.prepare(dn_);
HITCBC 28   21044 if(dn_ > 0) 28   21044 if(dn_ > 0)
HITCBC 29   19224 detail::decode_unsafe( 29   19224 detail::decode_unsafe(
HITCBC 30   19224 p, p + dn_, s_, opt); 30   19224 p, p + dn_, s_, opt);
HITCBC 31   21044 } 31   21044 }
32   32  
33   //------------------------------------------------ 33   //------------------------------------------------
34   34  
HITCBC 35   8515 pct_string_view:: 35   8922 pct_string_view::
36   pct_string_view( 36   pct_string_view(
HITCBC 37   8515 core::string_view s) 37   8922 core::string_view s)
38   : pct_string_view( 38   : pct_string_view(
HITCBC 39   8515 make_pct_string_view(s 39   8922 make_pct_string_view(s
HITCBC 40   8515 ).value(BOOST_URL_POS)) 40   8922 ).value(BOOST_URL_POS))
41   { 41   {
HITCBC 42   8278 } 42   8685 }
43   43  
44   //------------------------------------------------ 44   //------------------------------------------------
45   45  
46   system::result<pct_string_view> 46   system::result<pct_string_view>
HITCBC 47   8559 make_pct_string_view( 47   8966 make_pct_string_view(
48   core::string_view s) noexcept 48   core::string_view s) noexcept
49   { 49   {
HITCBC 50   8559 auto p = s.begin(); 50   8966 auto p = s.begin();
HITCBC 51   8559 auto const end = s.end(); 51   8966 auto const end = s.end();
HITCBC 52   8559 std::size_t dn = 0; 52   8966 std::size_t dn = 0;
HITCBC 53   8559 if(s.size() >= 3) 53   8966 if(s.size() >= 3)
54   { 54   {
HITCBC 55   5868 auto const safe_end = end - 2; 55   6247 auto const safe_end = end - 2;
HITCBC 56   1181192 while(p < safe_end) 56   1191946 while(p < safe_end)
57   { 57   {
HITCBC 58   1175421 if(*p != '%') 58   1185796 if(*p != '%')
59   { 59   {
HITCBC 60   952713 ++p; 60   962884 ++p;
61   } 61   }
HITCBC 62   222708 else if( 62   222912 else if(
HITCBC 63   445330 grammar::hexdig_value(p[1]) >= 0 && 63   445738 grammar::hexdig_value(p[1]) >= 0 &&
HITCBC 64   222622 grammar::hexdig_value(p[2]) >= 0) 64   222826 grammar::hexdig_value(p[2]) >= 0)
65   { 65   {
66   // percent-escape 66   // percent-escape
HITCBC 67   222611 p += 3; 67   222815 p += 3;
68   } 68   }
69   else 69   else
70   { 70   {
71   // invalid encoding 71   // invalid encoding
HITCBC 72   97 BOOST_URL_RETURN_EC( 72   97 BOOST_URL_RETURN_EC(
73   error::bad_pct_hexdig); 73   error::bad_pct_hexdig);
74   } 74   }
HITCBC 75   1175324 ++dn; 75   1185699 ++dn;
76   } 76   }
77   } 77   }
HITCBC 78   8462 auto const n = end - p; 78   8869 auto const n = end - p;
HITCBC 79   8462 if( (n >= 1 && p[0] == '%') || 79   8869 if( (n >= 1 && p[0] == '%') ||
HITCBC 80   4857 (n >= 2 && p[1] == '%')) 80   5216 (n >= 2 && p[1] == '%'))
81   { 81   {
82   // invalid encoding 82   // invalid encoding
HITCBC 83   143 BOOST_URL_RETURN_EC( 83   143 BOOST_URL_RETURN_EC(
84   error::incomplete_encoding); 84   error::incomplete_encoding);
85   } 85   }
HITCBC 86   8319 dn += n; 86   8726 dn += n;
HITCBC 87   16638 return make_pct_string_view_unsafe( 87   17452 return make_pct_string_view_unsafe(
HITCBC 88   8319 s.data(), s.size(), dn); 88   8726 s.data(), s.size(), dn);
89   } 89   }
90   90  
91   } // urls 91   } // urls
92   } // boost 92   } // boost
93   93