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

90.0% Lines (27/30) 100.0% Functions (1/1) 88.9% Branches (16/18)
include/boost/url/rfc/impl/query_rule.hpp
Line Branch Hits 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_IMPL_QUERY_RULE_HPP
12 #define BOOST_URL_RFC_IMPL_QUERY_RULE_HPP
13
14 #include <boost/url/detail/config.hpp>
15 #include <boost/url/rfc/detail/charsets.hpp>
16 #include <boost/url/error.hpp>
17 #include <boost/url/grammar/hexdig_chars.hpp>
18
19 namespace boost {
20 namespace urls {
21
22 inline
23 auto
24 129 implementation_defined::query_rule_t::
25 parse(
26 char const*& it,
27 char const* end
28 ) const noexcept ->
29 system::result<value_type>
30 {
31
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 129 times.
129 if(it == end)
32 {
33 core::string_view str(it, 0);
34 return params_encoded_view(
35 detail::query_ref(str, 0, 1));
36 }
37 129 auto const it0 = it;
38 129 std::size_t dn = 0;
39 129 std::size_t nparam = 1;
40
2/2
✓ Branch 0 taken 3059 times.
✓ Branch 1 taken 117 times.
3176 while(it != end)
41 {
42
2/2
✓ Branch 0 taken 211 times.
✓ Branch 1 taken 2848 times.
3059 if(*it == '&')
43 {
44 211 ++nparam;
45 211 ++it;
46 211 continue;
47 }
48
2/2
✓ Branch 1 taken 2785 times.
✓ Branch 2 taken 63 times.
2848 if(detail::query_chars(*it))
49 {
50 2785 ++it;
51 2785 continue;
52 }
53
2/2
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 2 times.
63 if(*it == '%')
54 {
55
4/4
✓ Branch 0 taken 53 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 51 times.
114 if(end - it < 3 ||
56
1/2
✓ Branch 1 taken 53 times.
✗ Branch 2 not taken.
53 (!grammar::hexdig_chars(it[1]) ||
57
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 51 times.
53 !grammar::hexdig_chars(it[2])))
58 {
59 10 break;
60 }
61 51 it += 3;
62 51 dn += 2;
63 51 continue;
64 }
65 2 break;
66 }
67 129 std::size_t const n(it - it0);
68 129 core::string_view str(it0, n);
69 129 return params_encoded_view(
70 258 detail::query_ref(
71 129 str, n - dn, nparam));
72 }
73
74 } // urls
75 } // boost
76
77
78 #endif
79