96.97% Lines (32/33) 100.00% Functions (1/1)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) 2   // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3   // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com) 3   // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
4   // 4   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 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) 6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 7   //
8   // Official repository: https://github.com/boostorg/url 8   // Official repository: https://github.com/boostorg/url
9   // 9   //
10   10  
11   #ifndef BOOST_URL_RFC_IMPL_URI_RULE_HPP 11   #ifndef BOOST_URL_RFC_IMPL_URI_RULE_HPP
12   #define BOOST_URL_RFC_IMPL_URI_RULE_HPP 12   #define BOOST_URL_RFC_IMPL_URI_RULE_HPP
13   13  
14   #include <boost/url/detail/config.hpp> 14   #include <boost/url/detail/config.hpp>
15   #include <boost/url/url_view.hpp> 15   #include <boost/url/url_view.hpp>
16   #include <boost/url/grammar/delim_rule.hpp> 16   #include <boost/url/grammar/delim_rule.hpp>
17   #include <boost/url/grammar/tuple_rule.hpp> 17   #include <boost/url/grammar/tuple_rule.hpp>
18   #include <boost/url/grammar/optional_rule.hpp> 18   #include <boost/url/grammar/optional_rule.hpp>
19   #include <boost/url/grammar/parse.hpp> 19   #include <boost/url/grammar/parse.hpp>
20   #include <boost/url/rfc/detail/fragment_part_rule.hpp> 20   #include <boost/url/rfc/detail/fragment_part_rule.hpp>
21   #include <boost/url/rfc/detail/hier_part_rule.hpp> 21   #include <boost/url/rfc/detail/hier_part_rule.hpp>
22   #include <boost/url/rfc/detail/query_part_rule.hpp> 22   #include <boost/url/rfc/detail/query_part_rule.hpp>
23   #include <boost/url/rfc/detail/scheme_rule.hpp> 23   #include <boost/url/rfc/detail/scheme_rule.hpp>
24   24  
25   namespace boost { 25   namespace boost {
26   namespace urls { 26   namespace urls {
27   27  
28   BOOST_URL_CXX20_CONSTEXPR_OR_INLINE 28   BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
29   auto 29   auto
HITCBC 30   20068 implementation_defined::uri_rule_t:: 30   20072 implementation_defined::uri_rule_t::
31   parse( 31   parse(
32   char const*& it, 32   char const*& it,
33   char const* const end 33   char const* const end
34   ) const noexcept -> 34   ) const noexcept ->
35   system::result<value_type> 35   system::result<value_type>
36   { 36   {
HITCBC 37   20068 detail::url_impl u(detail::url_impl::from::string); 37   20072 detail::url_impl u(detail::url_impl::from::string);
HITCBC 38   20068 u.cs_ = it; 38   20072 u.cs_ = it;
39   39  
40   // scheme 40   // scheme
41   { 41   {
HITCBC 42   20068 auto rv = grammar::parse( 42   20072 auto rv = grammar::parse(
43   it, end, 43   it, end,
HITCBC 44   20068 grammar::tuple_rule( 44   20072 grammar::tuple_rule(
HITCBC 45   20068 detail::scheme_rule(), 45   20072 detail::scheme_rule(),
HITCBC 46   20068 grammar::squelch( 46   20072 grammar::squelch(
HITCBC 47   20068 grammar::delim_rule(':')))); 47   20072 grammar::delim_rule(':'))));
HITCBC 48   20068 if(! rv) 48   20072 if(! rv)
HITCBC 49   12859 return rv.error(); 49   12863 return rv.error();
HITCBC 50   7209 u.apply_scheme(rv->scheme); 50   7209 u.apply_scheme(rv->scheme);
51   } 51   }
52   52  
53   // hier_part 53   // hier_part
54   { 54   {
55   auto rv = grammar::parse( 55   auto rv = grammar::parse(
56   it, end, 56   it, end,
HITCBC 57   7209 detail::hier_part_rule); 57   7209 detail::hier_part_rule);
HITCBC 58   7209 if(! rv) 58   7209 if(! rv)
HITCBC 59   43 return rv.error(); 59   43 return rv.error();
HITCBC 60   7166 if(rv->has_authority) 60   7166 if(rv->has_authority)
HITCBC 61   6149 u.apply_authority(rv->authority.u_); 61   6149 u.apply_authority(rv->authority.u_);
HITCBC 62   14332 u.apply_path( 62   14332 u.apply_path(
HITCBC 63   7166 rv->path, 63   7166 rv->path,
HITCBC 64   7166 rv->segment_count); 64   7166 rv->segment_count);
HITCBC 65   7209 } 65   7209 }
66   66  
67   // [ "?" query ] 67   // [ "?" query ]
68   { 68   {
HITCBC 69   7166 auto rv = grammar::parse( 69   7166 auto rv = grammar::parse(
70   it, end, detail::query_part_rule); 70   it, end, detail::query_part_rule);
HITCBC 71   7166 if(! rv) 71   7166 if(! rv)
MISUBC 72   return rv.error(); 72   return rv.error();
HITCBC 73   7166 if(rv->has_query) 73   7166 if(rv->has_query)
74   { 74   {
75   // map "?" to { {} } 75   // map "?" to { {} }
HITCBC 76   7146 u.apply_query( 76   7146 u.apply_query(
HITCBC 77   3573 rv->query, 77   3573 rv->query,
HITCBC 78   3573 rv->count); 78   3573 rv->count);
79   } 79   }
80   } 80   }
81   81  
82   // [ "#" fragment ] 82   // [ "#" fragment ]
83   { 83   {
HITCBC 84   7166 auto rv = grammar::parse( 84   7166 auto rv = grammar::parse(
85   it, end, detail::fragment_part_rule); 85   it, end, detail::fragment_part_rule);
HITCBC 86   7166 if(! rv) 86   7166 if(! rv)
HITCBC 87   1 return rv.error(); 87   1 return rv.error();
HITCBC 88   7165 if(rv->has_fragment) 88   7165 if(rv->has_fragment)
HITCBC 89   500 u.apply_frag(rv->fragment); 89   500 u.apply_frag(rv->fragment);
90   } 90   }
91   91  
HITCBC 92   7165 return url_view(u); 92   7165 return url_view(u);
93   } 93   }
94   94  
95   } // urls 95   } // urls
96   } // boost 96   } // boost
97   97  
98   98  
99   #endif 99   #endif