96.67% Lines (58/60) 100.00% Functions (1/1)
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) 2023 Alan de Freitas (alandefreitas@gmail.com) 3   // Copyright (c) 2023 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_DETAIL_IMPL_RELATIVE_PART_RULE_HPP 11   #ifndef BOOST_URL_RFC_DETAIL_IMPL_RELATIVE_PART_RULE_HPP
12   #define BOOST_URL_RFC_DETAIL_IMPL_RELATIVE_PART_RULE_HPP 12   #define BOOST_URL_RFC_DETAIL_IMPL_RELATIVE_PART_RULE_HPP
13   13  
14   #include <boost/url/detail/config.hpp> 14   #include <boost/url/detail/config.hpp>
15   #include <boost/url/rfc/detail/path_rules.hpp> 15   #include <boost/url/rfc/detail/path_rules.hpp>
16   #include <boost/url/rfc/pct_encoded_rule.hpp> 16   #include <boost/url/rfc/pct_encoded_rule.hpp>
17   #include <boost/url/rfc/pchars.hpp> 17   #include <boost/url/rfc/pchars.hpp>
18   #include <boost/url/grammar/error.hpp> 18   #include <boost/url/grammar/error.hpp>
19   #include <boost/url/grammar/parse.hpp> 19   #include <boost/url/grammar/parse.hpp>
20   20  
21   namespace boost { 21   namespace boost {
22   namespace urls { 22   namespace urls {
23   namespace detail { 23   namespace detail {
24   24  
25   BOOST_URL_CXX20_CONSTEXPR_OR_INLINE 25   BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
26   auto 26   auto
HITCBC 27   13131 relative_part_rule_t:: 27   13135 relative_part_rule_t::
28   parse( 28   parse(
29   char const*& it, 29   char const*& it,
30   char const* const end 30   char const* const end
31   ) const noexcept -> 31   ) const noexcept ->
32   system::result<value_type> 32   system::result<value_type>
33   { 33   {
HITCBC 34   13131 constexpr auto pchars_nc = pchars - ':'; 34   13135 constexpr auto pchars_nc = pchars - ':';
35   35  
HITCBC 36   13131 value_type t; 36   13135 value_type t;
HITCBC 37   13131 if(it == end) 37   13135 if(it == end)
38   { 38   {
39   // path-empty 39   // path-empty
HITCBC 40   153 return t; 40   153 return t;
41   } 41   }
HITCBC 42   12978 if(end - it == 1) 42   12982 if(end - it == 1)
43   { 43   {
HITCBC 44   188 if(*it == '/') 44   188 if(*it == '/')
45   { 45   {
46   // path-absolute 46   // path-absolute
HITCBC 47   83 t.path = make_pct_string_view_unsafe( 47   83 t.path = make_pct_string_view_unsafe(
48   it, 1, 1); 48   it, 1, 1);
HITCBC 49   83 t.segment_count = 1; 49   83 t.segment_count = 1;
HITCBC 50   83 ++it; 50   83 ++it;
HITCBC 51   83 return t; 51   83 return t;
52   } 52   }
HITCBC 53   105 if(*it != ':') 53   105 if(*it != ':')
54   { 54   {
55   // path-noscheme or 55   // path-noscheme or
56   // path-empty 56   // path-empty
HITCBC 57   104 auto rv = grammar::parse( 57   104 auto rv = grammar::parse(
58   it, end, segment_rule); 58   it, end, segment_rule);
HITCBC 59   104 if(! rv) 59   104 if(! rv)
MISUBC 60   return rv.error(); 60   return rv.error();
HITCBC 61   104 if(! rv->empty()) 61   104 if(! rv->empty())
62   { 62   {
HITCBC 63   52 t.path = *rv; 63   52 t.path = *rv;
HITCBC 64   52 t.segment_count = 1; 64   52 t.segment_count = 1;
65   } 65   }
66   } 66   }
67   // path-empty 67   // path-empty
HITCBC 68   105 return t; 68   105 return t;
69   } 69   }
HITCBC 70   12790 if( it[0] == '/' && 70   12794 if( it[0] == '/' &&
HITCBC 71   675 it[1] == '/') 71   675 it[1] == '/')
72   { 72   {
73   // "//" authority 73   // "//" authority
HITCBC 74   255 it += 2; 74   255 it += 2;
75   auto rv = grammar::parse( 75   auto rv = grammar::parse(
HITCBC 76   255 it, end, authority_rule); 76   255 it, end, authority_rule);
HITCBC 77   255 if(! rv) 77   255 if(! rv)
MISUBC 78   return rv.error(); 78   return rv.error();
HITCBC 79   255 t.authority = *rv; 79   255 t.authority = *rv;
HITCBC 80   255 t.has_authority = true; 80   255 t.has_authority = true;
HITCBC 81   255 } 81   255 }
HITCBC 82   12790 if(it == end) 82   12794 if(it == end)
83   { 83   {
84   // path-empty 84   // path-empty
HITCBC 85   129 return t; 85   129 return t;
86   } 86   }
HITCBC 87   12661 auto const it0 = it; 87   12665 auto const it0 = it;
HITCBC 88   12661 std::size_t dn = 0; 88   12665 std::size_t dn = 0;
HITCBC 89   12661 if(*it != '/') 89   12665 if(*it != '/')
90   { 90   {
91   // segment_nc 91   // segment_nc
HITCBC 92   12118 auto rv = grammar::parse(it, end, 92   12122 auto rv = grammar::parse(it, end,
HITCBC 93   12118 pct_encoded_rule(pchars_nc)); 93   12122 pct_encoded_rule(pchars_nc));
HITCBC 94   12118 if(! rv) 94   12122 if(! rv)
HITCBC 95   121 return rv.error(); 95   121 return rv.error();
HITCBC 96   11997 if(rv->empty()) 96   12001 if(rv->empty())
HITCBC 97   2325 return t; 97   2329 return t;
HITCBC 98   9672 dn += rv->decoded_size(); 98   9672 dn += rv->decoded_size();
HITCBC 99   9672 ++t.segment_count; 99   9672 ++t.segment_count;
HITCBC 100   9672 if( it != end && 100   9672 if( it != end &&
HITCBC 101   9524 *it == ':') 101   9524 *it == ':')
102   { 102   {
HITCBC 103   415 BOOST_URL_CONSTEXPR_RETURN_EC( 103   415 BOOST_URL_CONSTEXPR_RETURN_EC(
104   grammar::error::mismatch); 104   grammar::error::mismatch);
105   } 105   }
106   } 106   }
HITCBC 107   13639 while(it != end) 107   13639 while(it != end)
108   { 108   {
HITCBC 109   12864 if(*it == '/') 109   12864 if(*it == '/')
110   { 110   {
HITCBC 111   2097 ++dn; 111   2097 ++dn;
HITCBC 112   2097 ++it; 112   2097 ++it;
HITCBC 113   2097 ++t.segment_count; 113   2097 ++t.segment_count;
HITCBC 114   2097 continue; 114   2097 continue;
115   } 115   }
HITCBC 116   10767 auto rv = grammar::parse( 116   10767 auto rv = grammar::parse(
117   it, end, segment_rule); 117   it, end, segment_rule);
HITCBC 118   10767 if(! rv) 118   10767 if(! rv)
HITCBC 119   4 return rv.error(); 119   4 return rv.error();
HITCBC 120   10763 if(rv->empty()) 120   10763 if(rv->empty())
HITCBC 121   9021 break; 121   9021 break;
HITCBC 122   1742 dn += rv->decoded_size(); 122   1742 dn += rv->decoded_size();
123   } 123   }
HITCBC 124   9796 t.path = make_pct_string_view_unsafe( 124   9796 t.path = make_pct_string_view_unsafe(
HITCBC 125   9796 it0, it - it0, dn); 125   9796 it0, it - it0, dn);
HITCBC 126   9796 return t; 126   9796 return t;
HITCBC 127   13131 } 127   13135 }
128   128  
129   } // detail 129   } // detail
130   } // urls 130   } // urls
131   } // boost 131   } // boost
132   132  
133   133  
134   #endif 134   #endif