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_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 0 : core::string_view str(it, 0);
34 0 : return params_encoded_view(
35 0 : 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 3176 : while(it != end)
41 : {
42 3059 : if(*it == '&')
43 : {
44 211 : ++nparam;
45 211 : ++it;
46 211 : continue;
47 : }
48 2848 : if(detail::query_chars(*it))
49 : {
50 2785 : ++it;
51 2785 : continue;
52 : }
53 63 : if(*it == '%')
54 : {
55 114 : if(end - it < 3 ||
56 53 : (!grammar::hexdig_chars(it[1]) ||
57 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
|