LCOV - code coverage report
Current view: top level - libs/url/src/rfc/detail - ipv6_addrz_rule.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 19 19 100.0 %
Date: 2024-03-12 19:37:18 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.15