LCOV - code coverage report
Current view: top level - libs/url/src/rfc/detail/ip_literal_rule.cpp (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 91.9 % 37 34
Test Date: 2025-11-10 19:06:20 Functions: 100.0 % 1 1

            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           63 : 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           63 :     value_type t;
      34              : 
      35              :     // '['
      36              :     {
      37           63 :         auto rv = grammar::parse(
      38           63 :             it, end, grammar::delim_rule('['));
      39           63 :         if(! rv)
      40            0 :             return rv.error();
      41              :     }
      42           63 :     if(it == end)
      43              :     {
      44              :         // end
      45            0 :         BOOST_URL_RETURN_EC(
      46              :             grammar::error::invalid);
      47              :     }
      48           63 :     if(*it != 'v')
      49              :     {
      50              :         // IPv6address
      51           58 :         auto it0 = it;
      52           58 :         auto rv = grammar::parse(
      53              :             it, end,
      54           58 :             grammar::tuple_rule(
      55              :                 ipv6_address_rule,
      56           58 :                 grammar::squelch(
      57           58 :                     grammar::delim_rule(']'))));
      58           58 :         if(! rv)
      59              :         {
      60              :             // IPv6addrz: https://datatracker.ietf.org/doc/html/rfc6874
      61           29 :             it = it0;
      62           29 :             auto rv2 = grammar::parse(
      63              :                 it, end,
      64           29 :                 grammar::tuple_rule(
      65              :                     ipv6_addrz_rule,
      66           29 :                     grammar::squelch(
      67           29 :                         grammar::delim_rule(']'))));
      68           29 :             if(! rv2)
      69           24 :                 return rv2.error();
      70            5 :             t.ipv6 = rv2->ipv6;
      71            5 :             t.is_ipv6 = true;
      72            5 :             return t;
      73              :         }
      74           29 :         t.ipv6 = *rv;
      75           29 :         t.is_ipv6 = true;
      76           29 :         return t;
      77              :     }
      78              :     {
      79              :         // IPvFuture
      80            5 :         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 2.1