100.00% Lines (20/20) 100.00% Functions (1/1)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com) 2   // Copyright (c) 2023 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   #ifndef BOOST_URL_RFC_DETAIL_IMPL_IPV6_ADDRZ_RULE_HPP 10   #ifndef BOOST_URL_RFC_DETAIL_IMPL_IPV6_ADDRZ_RULE_HPP
11   #define BOOST_URL_RFC_DETAIL_IMPL_IPV6_ADDRZ_RULE_HPP 11   #define BOOST_URL_RFC_DETAIL_IMPL_IPV6_ADDRZ_RULE_HPP
12   12  
13   #include <boost/url/detail/config.hpp> 13   #include <boost/url/detail/config.hpp>
14   #include <boost/url/grammar/error.hpp> 14   #include <boost/url/grammar/error.hpp>
15   #include <boost/url/grammar/parse.hpp> 15   #include <boost/url/grammar/parse.hpp>
16   #include <boost/url/rfc/ipv6_address_rule.hpp> 16   #include <boost/url/rfc/ipv6_address_rule.hpp>
17   #include <boost/url/rfc/unreserved_chars.hpp> 17   #include <boost/url/rfc/unreserved_chars.hpp>
18   #include <boost/url/rfc/pct_encoded_rule.hpp> 18   #include <boost/url/rfc/pct_encoded_rule.hpp>
19   19  
20   namespace boost { 20   namespace boost {
21   namespace urls { 21   namespace urls {
22   namespace detail { 22   namespace detail {
23   23  
24   BOOST_URL_CXX20_CONSTEXPR_OR_INLINE 24   BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
25   auto 25   auto
HITCBC 26   29 ipv6_addrz_rule_t:: 26   29 ipv6_addrz_rule_t::
27   parse( 27   parse(
28   char const*& it, 28   char const*& it,
29   char const* const end 29   char const* const end
30   ) const noexcept -> 30   ) const noexcept ->
31   system::result<value_type> 31   system::result<value_type>
32   { 32   {
HITCBC 33   29 value_type t; 33   29 value_type t;
HITCBC 34   29 auto rv1 = grammar::parse( 34   29 auto rv1 = grammar::parse(
35   it, end, ipv6_address_rule); 35   it, end, ipv6_address_rule);
HITCBC 36   29 if (! rv1) 36   29 if (! rv1)
HITCBC 37   17 return rv1.error(); 37   17 return rv1.error();
HITCBC 38   12 t.ipv6 = *rv1; 38   12 t.ipv6 = *rv1;
39   39  
40   // "%25" 40   // "%25"
HITCBC 41   12 auto it0 = it; 41   12 auto it0 = it;
HITCBC 42   12 if (end - it < 3 || 42   12 if (end - it < 3 ||
HITCBC 43   10 *it != '%' || 43   10 *it != '%' ||
HITCBC 44   7 *(it + 1) != '2' || 44   7 *(it + 1) != '2' ||
HITCBC 45   6 *(it + 2) != '5') 45   6 *(it + 2) != '5')
46   { 46   {
HITCBC 47   6 BOOST_URL_CONSTEXPR_RETURN_EC( 47   6 BOOST_URL_CONSTEXPR_RETURN_EC(
48   grammar::error::invalid); 48   grammar::error::invalid);
49   } 49   }
HITCBC 50   6 it += 3; 50   6 it += 3;
51   51  
52   // ZoneID = 1*( unreserved / pct-encoded ) 52   // ZoneID = 1*( unreserved / pct-encoded )
53   // Parse as many (unreserved / pct-encoded) 53   // Parse as many (unreserved / pct-encoded)
54   // as available 54   // as available
HITCBC 55   6 auto rv2 = grammar::parse( 55   6 auto rv2 = grammar::parse(
56   it, end, 56   it, end,
HITCBC 57   6 pct_encoded_rule(unreserved_chars)); 57   6 pct_encoded_rule(unreserved_chars));
HITCBC 58   6 if(!rv2 || rv2->empty()) 58   6 if(!rv2 || rv2->empty())
59   { 59   {
HITCBC 60   1 it = it0; 60   1 it = it0;
HITCBC 61   1 BOOST_URL_CONSTEXPR_RETURN_EC( 61   1 BOOST_URL_CONSTEXPR_RETURN_EC(
62   grammar::error::invalid); 62   grammar::error::invalid);
63   } 63   }
64   else 64   else
65   { 65   {
HITCBC 66   5 t.zone_id = *rv2; 66   5 t.zone_id = *rv2;
67   } 67   }
HITCBC 68   5 return t; 68   5 return t;
69   } 69   }
70   70  
71   } // detail 71   } // detail
72   } // urls 72   } // urls
73   } // boost 73   } // boost
74   74  
75   75  
76   #endif 76   #endif