94.74% Lines (36/38) 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_IP_LITERAL_RULE_HPP 11   #ifndef BOOST_URL_RFC_DETAIL_IMPL_IP_LITERAL_RULE_HPP
12   #define BOOST_URL_RFC_DETAIL_IMPL_IP_LITERAL_RULE_HPP 12   #define BOOST_URL_RFC_DETAIL_IMPL_IP_LITERAL_RULE_HPP
13   13  
14   #include <boost/url/detail/config.hpp> 14   #include <boost/url/detail/config.hpp>
15   #include <boost/url/rfc/ipv6_address_rule.hpp> 15   #include <boost/url/rfc/ipv6_address_rule.hpp>
16   #include <boost/url/rfc/detail/ipv6_addrz_rule.hpp> 16   #include <boost/url/rfc/detail/ipv6_addrz_rule.hpp>
17   #include <boost/url/rfc/detail/ipvfuture_rule.hpp> 17   #include <boost/url/rfc/detail/ipvfuture_rule.hpp>
18   #include <boost/url/grammar/delim_rule.hpp> 18   #include <boost/url/grammar/delim_rule.hpp>
19   #include <boost/url/grammar/error.hpp> 19   #include <boost/url/grammar/error.hpp>
20   #include <boost/url/grammar/parse.hpp> 20   #include <boost/url/grammar/parse.hpp>
21   #include <boost/url/grammar/tuple_rule.hpp> 21   #include <boost/url/grammar/tuple_rule.hpp>
22   22  
23   namespace boost { 23   namespace boost {
24   namespace urls { 24   namespace urls {
25   namespace detail { 25   namespace detail {
26   26  
27   BOOST_URL_CXX20_CONSTEXPR_OR_INLINE 27   BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
28   auto 28   auto
HITCBC 29   92 ip_literal_rule_t:: 29   92 ip_literal_rule_t::
30   parse( 30   parse(
31   char const*& it, 31   char const*& it,
32   char const* const end 32   char const* const end
33   ) const noexcept -> 33   ) const noexcept ->
34   system::result<value_type> 34   system::result<value_type>
35   { 35   {
HITCBC 36   92 value_type t; 36   92 value_type t;
37   37  
38   // '[' 38   // '['
39   { 39   {
HITCBC 40   92 auto rv = grammar::parse( 40   92 auto rv = grammar::parse(
HITCBC 41   92 it, end, grammar::delim_rule('[')); 41   92 it, end, grammar::delim_rule('['));
HITCBC 42   92 if(! rv) 42   92 if(! rv)
MISUBC 43   ✗ return rv.error(); 43   ✗ return rv.error();
44   } 44   }
HITCBC 45   92 if(it == end) 45   92 if(it == end)
46   { 46   {
47   // end 47   // end
HITCBC 48   1 BOOST_URL_CONSTEXPR_RETURN_EC( 48   1 BOOST_URL_CONSTEXPR_RETURN_EC(
49   grammar::error::invalid); 49   grammar::error::invalid);
50   } 50   }
HITCBC 51   91 if(*it != 'v') 51   91 if(*it != 'v')
52   { 52   {
53   // IPv6address 53   // IPv6address
HITCBC 54   86 auto it0 = it; 54   86 auto it0 = it;
HITCBC 55   86 auto rv = grammar::parse( 55   86 auto rv = grammar::parse(
56   it, end, 56   it, end,
HITCBC 57   86 grammar::tuple_rule( 57   86 grammar::tuple_rule(
58   ipv6_address_rule, 58   ipv6_address_rule,
HITCBC 59   86 grammar::squelch( 59   86 grammar::squelch(
HITCBC 60   86 grammar::delim_rule(']')))); 60   86 grammar::delim_rule(']'))));
HITCBC 61   86 if(! rv) 61   86 if(! rv)
62   { 62   {
63   // IPv6addrz: https://datatracker.ietf.org/doc/html/rfc6874 63   // IPv6addrz: https://datatracker.ietf.org/doc/html/rfc6874
HITCBC 64   46 it = it0; 64   46 it = it0;
HITCBC 65   46 auto rv2 = grammar::parse( 65   46 auto rv2 = grammar::parse(
66   it, end, 66   it, end,
HITCBC 67   46 grammar::tuple_rule( 67   46 grammar::tuple_rule(
68   ipv6_addrz_rule, 68   ipv6_addrz_rule,
HITCBC 69   46 grammar::squelch( 69   46 grammar::squelch(
HITCBC 70   46 grammar::delim_rule(']')))); 70   46 grammar::delim_rule(']'))));
HITCBC 71   46 if(! rv2) 71   46 if(! rv2)
HITCBC 72   25 return rv2.error(); 72   25 return rv2.error();
HITCBC 73   21 t.ipv6 = rv2->ipv6; 73   21 t.ipv6 = rv2->ipv6;
HITCBC 74   21 t.zone_id = rv2->zone_id; 74   21 t.zone_id = rv2->zone_id;
HITCBC 75   21 t.is_ipv6 = true; 75   21 t.is_ipv6 = true;
HITCBC 76   21 return t; 76   21 return t;
77   } 77   }
HITCBC 78   40 t.ipv6 = *rv; 78   40 t.ipv6 = *rv;
HITCBC 79   40 t.is_ipv6 = true; 79   40 t.is_ipv6 = true;
HITCBC 80   40 return t; 80   40 return t;
81   } 81   }
82   { 82   {
83   // IPvFuture 83   // IPvFuture
HITCBC 84   5 auto rv = grammar::parse( 84   5 auto rv = grammar::parse(
85   it, end, 85   it, end,
HITCBC 86   5 grammar::tuple_rule( 86   5 grammar::tuple_rule(
87   ipvfuture_rule, 87   ipvfuture_rule,
HITCBC 88   5 grammar::squelch( 88   5 grammar::squelch(
HITCBC 89   5 grammar::delim_rule(']')))); 89   5 grammar::delim_rule(']'))));
HITCBC 90   5 if(! rv) 90   5 if(! rv)
MISUBC 91   ✗ return rv.error(); 91   ✗ return rv.error();
HITCBC 92   5 t.is_ipv6 = false; 92   5 t.is_ipv6 = false;
HITCBC 93   5 t.ipvfuture = rv->str; 93   5 t.ipvfuture = rv->str;
HITCBC 94   5 return t; 94   5 return t;
95   } 95   }
96   } 96   }
97   97  
98   } // detail 98   } // detail
99   } // urls 99   } // urls
100   } // boost 100   } // boost
101   101  
102   102  
103   #endif 103   #endif