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_HIER_PART_RULE_HPP
12 : #define BOOST_URL_RFC_DETAIL_IMPL_HIER_PART_RULE_HPP
13 :
14 : #include <boost/url/detail/config.hpp>
15 : #include <boost/url/rfc/detail/path_rules.hpp>
16 : #include <boost/url/grammar/parse.hpp>
17 :
18 : namespace boost {
19 : namespace urls {
20 : namespace detail {
21 :
22 : inline BOOST_URL_CXX20_CONSTEXPR
23 : auto
24 2430 : hier_part_rule_t::
25 : parse(
26 : char const*& it,
27 : char const* const end
28 : ) const noexcept ->
29 : system::result<value_type>
30 : {
31 2430 : value_type t;
32 2430 : if(it == end)
33 : {
34 44 : return t;
35 : }
36 2386 : if(end - it == 1)
37 : {
38 36 : if(*it == '/')
39 : {
40 26 : t.path = make_pct_string_view_unsafe(
41 : it, 1, 1);
42 26 : t.segment_count = 1;
43 26 : ++it;
44 26 : return t;
45 : }
46 10 : auto rv = grammar::parse(
47 : it, end, segment_rule);
48 10 : if(! rv)
49 0 : return rv.error();
50 10 : t.path = *rv;
51 10 : t.segment_count = !t.path.empty();
52 10 : return t;
53 : }
54 2350 : if( it[0] == '/' &&
55 1739 : it[1] == '/')
56 : {
57 1641 : it += 2;
58 : auto rv = grammar::parse(
59 1641 : it, end, authority_rule);
60 1641 : if(! rv)
61 30 : return rv.error();
62 1611 : t.authority = *rv;
63 1611 : t.has_authority = true;
64 1641 : }
65 2320 : if(it == end || (
66 1868 : t.has_authority && (
67 1159 : *it != '/' &&
68 150 : *it != '?' &&
69 105 : *it != '#')))
70 : {
71 541 : return t;
72 : }
73 1779 : auto const it0 = it;
74 1779 : std::size_t dn = 0;
75 1779 : if(*it != '/')
76 : {
77 672 : auto rv = grammar::parse(
78 : it, end, segment_rule);
79 672 : if(! rv)
80 2 : return rv.error();
81 670 : if(rv->empty())
82 79 : return t;
83 591 : dn += rv->decoded_size();
84 591 : ++t.segment_count;
85 : }
86 4954 : while(it != end)
87 : {
88 3497 : if(*it == '/')
89 : {
90 1918 : ++dn;
91 1918 : ++it;
92 1918 : ++t.segment_count;
93 1918 : continue;
94 : }
95 1579 : auto rv = grammar::parse(
96 : it, end, segment_rule);
97 1579 : if(! rv)
98 4 : return rv.error();
99 1575 : if(rv->empty())
100 237 : break;
101 1338 : dn += rv->decoded_size();
102 : }
103 1694 : t.path = make_pct_string_view_unsafe(
104 1694 : it0, it - it0, dn);
105 1694 : return t;
106 2430 : }
107 :
108 : } // detail
109 : } // urls
110 : } // boost
111 :
112 :
113 : #endif
|