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 574 : 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 574 : 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 541 : auto const it0 = it;
36 541 : std::size_t dn = 0;
37 541 : std::size_t nparam = 1;
38 7084 : while(it != end)
39 : {
40 6721 : if(*it == '&')
41 : {
42 462 : ++nparam;
43 462 : ++it;
44 462 : continue;
45 : }
46 6259 : if(detail::query_chars(*it))
47 : {
48 5952 : ++it;
49 5952 : continue;
50 : }
51 307 : if(*it == '%')
52 : {
53 273 : if(end - it < 3 ||
54 132 : (!grammar::hexdig_chars(it[1]) ||
55 131 : !grammar::hexdig_chars(it[2])))
56 : {
57 : // missing valid HEXDIG
58 12 : break;
59 : }
60 129 : it += 3;
61 129 : dn += 2;
62 129 : continue;
63 : }
64 : // got reserved character
65 166 : break;
66 : }
67 541 : std::size_t const n(it - it0);
68 541 : core::string_view str(it0, n);
69 541 : return params_encoded_view(
70 1082 : detail::query_ref(
71 541 : str, n - dn, nparam));
72 : }
73 :
74 : } // urls
75 : } // boost
76 :
|