LCOV - code coverage report
Current view: top level - libs/url/src/rfc/detail - ip_literal_rule.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 30 33 90.9 %
Date: 2024-03-13 19:32:03 Functions: 1 1 100.0 %

          Line data    Source code
       1             : //
       2             : // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
       3             : // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
       4             : //
       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)
       7             : //
       8             : // Official repository: https://github.com/boostorg/url
       9             : //
      10             : 
      11             : 
      12             : #include <boost/url/detail/config.hpp>
      13             : #include <boost/url/rfc/ipv6_address_rule.hpp>
      14             : #include "ip_literal_rule.hpp"
      15             : #include "ipv6_addrz_rule.hpp"
      16             : #include <boost/url/grammar/delim_rule.hpp>
      17             : #include <boost/url/grammar/parse.hpp>
      18             : #include <boost/url/grammar/tuple_rule.hpp>
      19             : #include "ipvfuture_rule.hpp"
      20             : 
      21             : namespace boost {
      22             : namespace urls {
      23             : namespace detail {
      24             : 
      25             : auto
      26          61 : ip_literal_rule_t::
      27             : parse(
      28             :     char const*& it,
      29             :     char const* const end
      30             :         ) const noexcept ->
      31             :     system::result<value_type>
      32             : {
      33          61 :     value_type t;
      34             : 
      35             :     // '['
      36             :     {
      37             :         auto rv = grammar::parse(
      38          61 :             it, end, grammar::delim_rule('['));
      39          61 :         if(! rv)
      40           0 :             return rv.error();
      41             :     }
      42          61 :     if(it == end)
      43             :     {
      44             :         // end
      45           0 :         BOOST_URL_RETURN_EC(
      46             :             grammar::error::invalid);
      47             :     }
      48          61 :     if(*it != 'v')
      49             :     {
      50             :         // IPv6address
      51          56 :         auto it0 = it;
      52             :         auto rv = grammar::parse(
      53             :             it, end,
      54          56 :             grammar::tuple_rule(
      55             :                 ipv6_address_rule,
      56          56 :                 grammar::squelch(
      57          56 :                     grammar::delim_rule(']'))));
      58          56 :         if(! rv)
      59             :         {
      60             :             // IPv6addrz
      61          27 :             it = it0;
      62             :             auto rv2 = grammar::parse(
      63             :                 it, end,
      64          27 :                 grammar::tuple_rule(
      65             :                     ipv6_addrz_rule,
      66          27 :                     grammar::squelch(
      67          27 :                         grammar::delim_rule(']'))));
      68          27 :             if(! rv2)
      69          24 :                 return rv2.error();
      70           3 :             t.ipv6 = rv2->ipv6;
      71           3 :             t.is_ipv6 = true;
      72           3 :             return t;
      73             :         }
      74          29 :         t.ipv6 = *rv;
      75          29 :         t.is_ipv6 = true;
      76          29 :         return t;
      77             :     }
      78             :     {
      79             :         // IPvFuture
      80             :         auto rv = grammar::parse(
      81             :             it, end, 
      82           5 :             grammar::tuple_rule(
      83             :                 ipvfuture_rule,
      84           5 :                 grammar::squelch(
      85           5 :                     grammar::delim_rule(']'))));
      86           5 :         if(! rv)
      87           0 :             return rv.error();
      88           5 :         t.is_ipv6 = false;
      89           5 :         t.ipvfuture = rv->str;
      90           5 :         return t;
      91             :     }
      92             : }
      93             : 
      94             : } // detail
      95             : } // urls
      96             : } // boost
      97             : 

Generated by: LCOV version 1.15