LCOV - code coverage report
Current view: top level - libs/url/src/rfc/detail - port_rule.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 43 44 97.7 %
Date: 2024-02-29 20:02:55 Functions: 2 2 100.0 %

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

Generated by: LCOV version 1.15