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

Generated by: LCOV version 1.15