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 +
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 +
    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 +
    auto const it0 = it;
 
38 +
    std::size_t dn = 0;
 
39 +
    std::size_t nparam = 1;
 
40 +
    while(it != end)
 
41 +
    {
 
42 +
        if(*it == '&')
 
43 +
        {
 
44 +
            ++nparam;
 
45 +
            ++it;
 
46 +
            continue;
 
47 +
        }
 
48 +
        if(detail::query_chars(*it))
 
49 +
        {
 
50 +
            ++it;
 
51 +
            continue;
 
52 +
        }
 
53 +
        if(*it == '%')
 
54 +
        {
 
55 +
            if(end - it < 3 ||
 
56 +
                (!grammar::hexdig_chars(it[1]) ||
 
57 +
                 !grammar::hexdig_chars(it[2])))
 
58 +
            {
 
59 +
                break;
 
60 +
            }
 
61 +
            it += 3;
 
62 +
            dn += 2;
 
63 +
            continue;
 
64 +
        }
 
65 +
        break;
 
66 +
    }
 
67 +
    std::size_t const n(it - it0);
 
68 +
    core::string_view str(it0, n);
 
69 +
    return params_encoded_view(
 
70 +
        detail::query_ref(
 
71 +
            str, n - dn, nparam));
 
72 +
}
 
73 +

 
74 +
} // urls
 
75 +
} // boost
 
76 +

 
77 +

 
78 +
#endif