src/parse_path.cpp

100.0% Lines (23/23) 100.0% List of functions (1/1)
parse_path.cpp
f(x) Functions (1)
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 // Copyright (c) 2022 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
12 #include <boost/url/detail/config.hpp>
13 #include <boost/url/parse_path.hpp>
14 #include <boost/url/error.hpp>
15 #include <boost/url/detail/path.hpp>
16 #include <boost/url/grammar/parse.hpp>
17 #include "boost/url/rfc/detail/path_rules.hpp"
18
19 namespace boost {
20 namespace urls {
21
22 system::result<segments_encoded_view>
23 3203x parse_path(core::string_view s) noexcept
24 {
25 3203x auto it = s.data();
26 3203x auto const end = it + s.size();
27 3203x std::size_t dn = 0;
28 3203x std::size_t nseg = 0;
29 3203x if( it != end &&
30 3195x *it != '/')
31 3114x ++nseg;
32 6913x while(it != end)
33 {
34 6714x if(*it == '/')
35 {
36 622x ++it;
37 622x ++dn;
38 622x ++nseg;
39 622x continue;
40 }
41 6092x auto rv = grammar::parse(
42 it, end, detail::segment_rule);
43 6092x if(! rv)
44 44x return rv.error();
45 6048x if(rv->empty())
46 {
47 2960x BOOST_URL_RETURN_EC(
48 grammar::error::mismatch);
49 }
50 3088x dn += rv->decoded_size();
51 }
52 // adjust nseg
53 199x nseg = detail::path_segments(s, nseg);
54 199x return segments_encoded_view(
55 398x detail::path_ref(s, dn, nseg));
56 }
57
58 } // urls
59 } // boost
60
61