LCOV - code coverage report
Current view: top level - url/rfc/detail/impl - port_rule.hpp (source / functions) Coverage Total Hit
Test: coverage_remapped.info Lines: 97.8 % 45 44
Test Date: 2026-02-13 15:53:22 Functions: 100.0 % 2 2

            Line data    Source code
       1              : //
       2              : // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
       3              : // Copyright (c) 2023 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              : #ifndef BOOST_URL_RFC_DETAIL_IMPL_PORT_RULE_HPP
      12              : #define BOOST_URL_RFC_DETAIL_IMPL_PORT_RULE_HPP
      13              : 
      14              : #include <boost/url/detail/config.hpp>
      15              : #include <boost/url/grammar/digit_chars.hpp>
      16              : #include <boost/url/grammar/parse.hpp>
      17              : #include <boost/url/grammar/unsigned_rule.hpp>
      18              : 
      19              : namespace boost {
      20              : namespace urls {
      21              : namespace detail {
      22              : 
      23              : inline BOOST_URL_CXX20_CONSTEXPR
      24              : auto
      25          395 : port_rule::
      26              : parse(
      27              :     char const*& it,
      28              :     char const* end) const noexcept ->
      29              :         system::result<value_type>
      30              : {
      31          395 :     value_type t;
      32          395 :     auto const start = it;
      33          395 :     while(
      34          523 :         it != end &&
      35          461 :         *it == '0')
      36              :     {
      37          128 :         ++it;
      38              :     }
      39              : 
      40          395 :     if (it != end)
      41              :     {
      42              :         grammar::unsigned_rule<std::uint16_t> r;
      43          333 :         auto it0 = it;
      44          333 :         auto rv = r.parse(it, end);
      45          333 :         if (rv)
      46              :         {
      47          279 :             t.str = core::string_view(start, it);
      48          279 :             t.has_number = true;
      49          279 :             t.number = *rv;
      50          300 :             return t;
      51              :         }
      52           54 :         it = it0;
      53           54 :         if (grammar::digit_chars(*it))
      54              :         {
      55           21 :             while (
      56          366 :                 it != end &&
      57          177 :                 grammar::digit_chars(*it))
      58              :             {
      59          168 :                 ++it;
      60              :             }
      61           21 :             t.str = core::string_view(start, it);
      62           21 :             t.has_number = true;
      63           21 :             t.number = 0;
      64           21 :             return t;
      65              :         }
      66              :     }
      67           95 :     t.str = core::string_view(start, it);
      68           95 :     t.has_number = it != end;
      69           95 :     t.number = 0;
      70           95 :     return t;
      71              : }
      72              : 
      73              : inline BOOST_URL_CXX20_CONSTEXPR
      74              : auto
      75         2042 : port_part_rule_t::
      76              : parse(
      77              :     char const*& it,
      78              :     char const* end) const noexcept ->
      79              :         system::result<value_type>
      80              : {
      81         2042 :     value_type t;
      82         2042 :     if( it == end ||
      83         1413 :         *it != ':')
      84              :     {
      85         1737 :         t.has_port = false;
      86         1737 :         return t;
      87              :     }
      88          305 :     ++it;
      89          305 :     auto rv = grammar::parse(
      90          305 :         it, end, port_rule{});
      91          305 :     if(! rv)
      92            0 :         return rv.error();
      93          305 :     t.has_port = true;
      94          305 :     t.port = rv->str;
      95          305 :     t.has_number = rv->has_number;
      96          305 :     t.port_number = rv->number;
      97          305 :     return t;
      98              : }
      99              : 
     100              : } // detail
     101              : } // urls
     102              : } // boost
     103              : 
     104              : 
     105              : #endif
        

Generated by: LCOV version 2.3