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

90.0% Lines (27/30) 100.0% Functions (1/1)
include/boost/url/rfc/impl/query_rule.hpp
Line TLA 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 129 if(it == end)
32 {
33 // empty string = 1 param
34 core::string_view str(it, 0);
35 return params_encoded_view(
36 detail::query_ref(str, 0, 1));
37 }
38 129 auto const it0 = it;
39 129 std::size_t dn = 0;
40 129 std::size_t nparam = 1;
41 3176 while(it != end)
42 {
43 3059 if(*it == '&')
44 {
45 211 ++nparam;
46 211 ++it;
47 211 continue;
48 }
49 2848 if(detail::query_chars(*it))
50 {
51 2785 ++it;
52 2785 continue;
53 }
54 63 if(*it == '%')
55 {
56 114 if(end - it < 3 ||
57 53 (!grammar::hexdig_chars(it[1]) ||
58 53 !grammar::hexdig_chars(it[2])))
59 {
60 // missing valid HEXDIG
61 10 break;
62 }
63 51 it += 3;
64 51 dn += 2;
65 51 continue;
66 }
67 // got reserved character
68 2 break;
69 }
70 129 std::size_t const n(it - it0);
71 129 core::string_view str(it0, n);
72 129 return params_encoded_view(
73 258 detail::query_ref(
74 129 str, n - dn, nparam));
75 }
76
77 } // urls
78 } // boost
79
80
81 #endif
82