LCOV - code coverage report
Current view: top level - libs/url/src/rfc - authority_rule.cpp (source / functions) Hit Total Coverage
Test: coverage_filtered.info Lines: 25 27 92.6 %
Date: 2024-02-29 20:02:55 Functions: 1 1 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_RFC_IMPL_AUTHORITY_RULE_IPP
      11             : #define BOOST_URL_RFC_IMPL_AUTHORITY_RULE_IPP
      12             : 
      13             : #include <boost/url/detail/config.hpp>
      14             : #include <boost/url/rfc/authority_rule.hpp>
      15             : #include <boost/url/grammar/delim_rule.hpp>
      16             : #include <boost/url/grammar/optional_rule.hpp>
      17             : #include <boost/url/grammar/parse.hpp>
      18             : #include <boost/url/grammar/tuple_rule.hpp>
      19             : #include "detail/host_rule.hpp"
      20             : #include "detail/port_rule.hpp"
      21             : #include "detail/userinfo_rule.hpp"
      22             : 
      23             : namespace boost {
      24             : namespace urls {
      25             : 
      26             : auto
      27        1879 : authority_rule_t::
      28             : parse(
      29             :     char const*& it,
      30             :     char const* const end
      31             :         ) const noexcept ->
      32             :     system::result<value_type>
      33             : {
      34        1879 :     detail::url_impl u(detail::url_impl::from::authority);
      35        1879 :     u.cs_ = it;
      36             : 
      37             :     // [ userinfo "@" ]
      38             :     {
      39             :         auto rv = grammar::parse(
      40             :             it, end,
      41        1879 :             grammar::optional_rule(
      42        1879 :                 grammar::tuple_rule(
      43             :                     detail::userinfo_rule,
      44        1879 :                     grammar::squelch(
      45        1879 :                         grammar::delim_rule('@')))));
      46        1879 :         if(! rv)
      47           0 :             return rv.error();
      48        1879 :         if(rv->has_value())
      49             :         {
      50         129 :             u.apply_userinfo(
      51         380 :                 (*rv)->user,
      52         380 :                 (*rv)->has_password
      53         251 :                 ? &(*rv)->password
      54             :                 : nullptr);
      55             :         }
      56             :     }
      57             : 
      58             :     // host
      59             :     {
      60             :         auto rv = grammar::parse(
      61        1879 :             it, end, detail::host_rule);
      62        1879 :         if(! rv)
      63          31 :             return rv.error();
      64        1848 :         u.apply_host(rv->host_type,
      65        1848 :             rv->match, rv->addr);
      66             :     }
      67             : 
      68             :     // [ ":" port ]
      69             :     {
      70             :         auto rv = grammar::parse(
      71        1848 :             it, end, detail::port_part_rule);
      72        1848 :         if(! rv)
      73           0 :             return rv.error();
      74        1848 :         if(rv->has_port)
      75         247 :             u.apply_port(
      76         247 :                 rv->port,
      77         247 :                 rv->port_number);
      78             :     }
      79             : 
      80        1848 :     return u.construct_authority();
      81             : }
      82             : 
      83             : } // urls
      84             : } // boost
      85             : 
      86             : #endif

Generated by: LCOV version 1.15