include/boost/url/rfc/impl/origin_form_rule.hpp

100.0% Lines (28/28) 100.0% List of functions (1/1)
origin_form_rule.hpp
f(x) Functions (1)
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3 // Copyright (c) 2024 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_IMPL_ORIGIN_FORM_RULE_HPP
12 #define BOOST_URL_RFC_IMPL_ORIGIN_FORM_RULE_HPP
13
14 #include <boost/url/detail/config.hpp>
15 #include <boost/url/url_view.hpp>
16 #include <boost/url/rfc/detail/path_rules.hpp>
17 #include <boost/url/rfc/detail/query_part_rule.hpp>
18 #include <boost/url/grammar/parse.hpp>
19
20 namespace boost {
21 namespace urls {
22
23 BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
24 auto
25 3059x implementation_defined::origin_form_rule_t::
26 parse(
27 char const*& it,
28 char const* end
29 ) const noexcept ->
30 system::result<value_type>
31 {
32 3059x detail::url_impl u(detail::url_impl::from::string);
33 3059x u.cs_ = it;
34
35 // absolute-path = 1*( "/" segment )
36 {
37 3059x if(it == end || *it != '/')
38 {
39 3000x BOOST_URL_CONSTEXPR_RETURN_EC(
40 grammar::error::mismatch);
41 }
42 59x auto const it0 = it;
43 59x std::size_t dn = 0;
44 59x std::size_t nseg = 0;
45 185x while(it != end)
46 {
47 173x if(*it == '/')
48 {
49 76x ++dn;
50 76x ++it;
51 76x ++nseg;
52 76x continue;
53 }
54 97x auto rv = grammar::parse(
55 it, end, detail::segment_rule);
56 97x if(! rv)
57 2x return rv.error();
58 95x if(rv->empty())
59 45x break;
60 50x dn += rv->decoded_size();
61 }
62 57x u.apply_path(
63 make_pct_string_view_unsafe(
64 57x it0, it - it0, dn),
65 nseg);
66 }
67
68 // [ "?" query ]
69 {
70 // query_part_rule always succeeds
71 57x auto rv = grammar::parse(
72 it, end, detail::query_part_rule);
73 57x if(rv->has_query)
74 {
75 // map "?" to { {} }
76 28x u.apply_query(
77 14x rv->query,
78 14x rv->count);
79 }
80 }
81
82 57x return url_view(u);
83 }
84
85 } // urls
86 } // boost
87
88
89 #endif
90