Line data Source code
1 : //
2 : // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3 : //
4 : // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 : //
7 : // Official repository: https://github.com/boostorg/url
8 : //
9 :
10 :
11 : #include <boost/url/detail/config.hpp>
12 : #include <boost/url/rfc/query_rule.hpp>
13 : #include "detail/charsets.hpp"
14 : #include <boost/url/error.hpp>
15 : #include <boost/url/grammar/hexdig_chars.hpp>
16 :
17 : namespace boost {
18 : namespace urls {
19 :
20 : auto
21 567 : implementation_defined::query_rule_t::
22 : parse(
23 : char const*& it,
24 : char const* end
25 : ) const noexcept ->
26 : system::result<value_type>
27 : {
28 567 : if(it == end)
29 : {
30 : // empty string = 1 param
31 33 : core::string_view str(it, 0);
32 33 : return params_encoded_view(
33 66 : detail::query_ref(str, 0, 1));
34 : }
35 534 : auto const it0 = it;
36 534 : std::size_t dn = 0;
37 534 : std::size_t nparam = 1;
38 6959 : while(it != end)
39 : {
40 6603 : if(*it == '&')
41 : {
42 455 : ++nparam;
43 455 : ++it;
44 455 : continue;
45 : }
46 6148 : if(detail::query_chars(*it))
47 : {
48 5876 : ++it;
49 5876 : continue;
50 : }
51 272 : if(*it == '%')
52 : {
53 203 : if(end - it < 3 ||
54 97 : (!grammar::hexdig_chars(it[1]) ||
55 96 : !grammar::hexdig_chars(it[2])))
56 : {
57 : // missing valid HEXDIG
58 12 : break;
59 : }
60 94 : it += 3;
61 94 : dn += 2;
62 94 : continue;
63 : }
64 : // got reserved character
65 166 : break;
66 : }
67 534 : std::size_t const n(it - it0);
68 534 : core::string_view str(it0, n);
69 534 : return params_encoded_view(
70 1068 : detail::query_ref(
71 534 : str, n - dn, nparam));
72 : }
73 :
74 : } // urls
75 : } // boost
76 :
|