100.00% Lines (36/36) 100.00% Functions (2/2)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) 2   // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3   // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) 3   // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
4   // 4   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 5   // Distributed under the Boost Software License, Version 1.0. (See accompanying
6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 7   //
8   // Official repository: https://github.com/boostorg/url 8   // Official repository: https://github.com/boostorg/url
9   // 9   //
10   10  
11   #ifndef BOOST_URL_RFC_IMPL_PCT_ENCODED_RULE_HPP 11   #ifndef BOOST_URL_RFC_IMPL_PCT_ENCODED_RULE_HPP
12   #define BOOST_URL_RFC_IMPL_PCT_ENCODED_RULE_HPP 12   #define BOOST_URL_RFC_IMPL_PCT_ENCODED_RULE_HPP
13   13  
14   #include <boost/url/grammar/charset.hpp> 14   #include <boost/url/grammar/charset.hpp>
15   #include <boost/url/grammar/error.hpp> 15   #include <boost/url/grammar/error.hpp>
16   #include <boost/url/grammar/hexdig_chars.hpp> 16   #include <boost/url/grammar/hexdig_chars.hpp>
17   17  
18   namespace boost { 18   namespace boost {
19   namespace urls { 19   namespace urls {
20   20  
21   namespace detail { 21   namespace detail {
22   22  
23   template<class CharSet> 23   template<class CharSet>
24   BOOST_URL_CXX20_CONSTEXPR 24   BOOST_URL_CXX20_CONSTEXPR
25   auto 25   auto
HITCBC 26   58395 parse_encoded( 26   58399 parse_encoded(
27   char const*& it, 27   char const*& it,
28   char const* end, 28   char const* end,
29   CharSet const& cs) noexcept -> 29   CharSet const& cs) noexcept ->
30   system::result<pct_string_view> 30   system::result<pct_string_view>
31   { 31   {
HITCBC 32   58395 auto const start = it; 32   58399 auto const start = it;
HITCBC 33   58395 std::size_t n = 0; 33   58399 std::size_t n = 0;
HITCBC 34   1181 for(;;) 34   1181 for(;;)
35   { 35   {
HITCBC 36   59576 auto it0 = it; 36   59580 auto it0 = it;
HITCBC 37   59576 it = grammar::find_if_not( 37   59580 it = grammar::find_if_not(
38   it0, end, cs); 38   it0, end, cs);
HITCBC 39   59576 n += it - it0; 39   59580 n += it - it0;
HITCBC 40   59576 if(it == end || *it != '%') 40   59580 if(it == end || *it != '%')
41   break; 41   break;
HITCBC 42   1465 bool at_end = false; 42   1465 bool at_end = false;
HITCBC 43   229 for(;;) 43   229 for(;;)
44   { 44   {
HITCBC 45   1694 ++it; 45   1694 ++it;
HITCBC 46   1694 if(it == end) 46   1694 if(it == end)
47   { 47   {
48   // expected HEXDIG 48   // expected HEXDIG
HITCBC 49   20 BOOST_URL_CONSTEXPR_RETURN_EC( 49   20 BOOST_URL_CONSTEXPR_RETURN_EC(
50   grammar::error::invalid); 50   grammar::error::invalid);
51   } 51   }
HITCBC 52   1674 auto r = grammar::hexdig_value(*it); 52   1674 auto r = grammar::hexdig_value(*it);
HITCBC 53   1674 if(r < 0) 53   1674 if(r < 0)
54   { 54   {
55   // expected HEXDIG 55   // expected HEXDIG
HITCBC 56   107 BOOST_URL_CONSTEXPR_RETURN_EC( 56   107 BOOST_URL_CONSTEXPR_RETURN_EC(
57   grammar::error::invalid); 57   grammar::error::invalid);
58   } 58   }
HITCBC 59   1567 ++it; 59   1567 ++it;
HITCBC 60   1567 if(it == end) 60   1567 if(it == end)
61   { 61   {
62   // expected HEXDIG 62   // expected HEXDIG
HITCBC 63   5 BOOST_URL_CONSTEXPR_RETURN_EC( 63   5 BOOST_URL_CONSTEXPR_RETURN_EC(
64   grammar::error::invalid); 64   grammar::error::invalid);
65   } 65   }
HITCBC 66   1562 r = grammar::hexdig_value(*it); 66   1562 r = grammar::hexdig_value(*it);
HITCBC 67   1562 if(r < 0) 67   1562 if(r < 0)
68   { 68   {
69   // expected HEXDIG 69   // expected HEXDIG
HITCBC 70   82 BOOST_URL_CONSTEXPR_RETURN_EC( 70   82 BOOST_URL_CONSTEXPR_RETURN_EC(
71   grammar::error::invalid); 71   grammar::error::invalid);
72   } 72   }
HITCBC 73   1480 ++n; 73   1480 ++n;
HITCBC 74   1480 ++it; 74   1480 ++it;
HITCBC 75   1480 if(it == end) 75   1480 if(it == end)
76   { 76   {
HITCBC 77   70 at_end = true; 77   70 at_end = true;
HITCBC 78   70 break; 78   70 break;
79   } 79   }
HITCBC 80   1410 if(*it != '%') 80   1410 if(*it != '%')
HITCBC 81   1181 break; 81   1181 break;
82   } 82   }
HITCBC 83   1251 if(at_end) 83   1251 if(at_end)
HITCBC 84   70 break; 84   70 break;
85   } 85   }
HITCBC 86   58181 return make_pct_string_view_unsafe( 86   58185 return make_pct_string_view_unsafe(
HITCBC 87   58181 start, it - start, n); 87   58185 start, it - start, n);
88   } 88   }
89   89  
90   } // detail 90   } // detail
91   91  
92   //------------------------------------------------ 92   //------------------------------------------------
93   93  
94   template<class CharSet> 94   template<class CharSet>
95   BOOST_URL_CXX20_CONSTEXPR 95   BOOST_URL_CXX20_CONSTEXPR
96   auto 96   auto
HITCBC 97   58395 implementation_defined::pct_encoded_rule_t<CharSet>:: 97   58399 implementation_defined::pct_encoded_rule_t<CharSet>::
98   parse( 98   parse(
99   char const*& it, 99   char const*& it,
100   char const* end) const noexcept -> 100   char const* end) const noexcept ->
101   system::result<value_type> 101   system::result<value_type>
102   { 102   {
HITCBC 103   58395 return detail::parse_encoded( 103   58399 return detail::parse_encoded(
HITCBC 104   58395 it, end, cs_); 104   58399 it, end, cs_);
105   } 105   }
106   106  
107   } // urls 107   } // urls
108   } // boost 108   } // boost
109   109  
110   #endif 110   #endif