| 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 | #ifndef BOOST_URL_RFC_IMPL_QUERY_RULE_IPP |
| 11 | #define BOOST_URL_RFC_IMPL_QUERY_RULE_IPP |
| 12 | |
| 13 | #include <boost/url/detail/config.hpp> |
| 14 | #include <boost/url/rfc/query_rule.hpp> |
| 15 | #include "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 | auto |
| 23 | query_rule_t:: |
| 24 | parse( |
| 25 | char const*& it, |
| 26 | char const* end |
| 27 | ) const noexcept -> |
| 28 | system::result<value_type> |
| 29 | { |
| 30 | if(it == end) |
| 31 | { |
| 32 | // empty string = 0 params |
| 33 | return params_encoded_view( |
| 34 | detail::query_ref( |
| 35 | core::string_view(it, 0), 0, 0)); |
| 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 | { |
| 57 | // missing HEXDIG |
| 58 | BOOST_URL_RETURN_EC( |
| 59 | error::missing_pct_hexdig); |
| 60 | } |
| 61 | if (!grammar::hexdig_chars(it[1]) || |
| 62 | !grammar::hexdig_chars(it[2])) |
| 63 | { |
| 64 | // expected HEXDIG |
| 65 | BOOST_URL_RETURN_EC( |
| 66 | error::bad_pct_hexdig); |
| 67 | } |
| 68 | it += 3; |
| 69 | dn += 2; |
| 70 | continue; |
| 71 | } |
| 72 | // got reserved character |
| 73 | break; |
| 74 | } |
| 75 | std::size_t const n(it - it0); |
| 76 | return params_encoded_view( |
| 77 | detail::query_ref( |
| 78 | core::string_view(it0, n), |
| 79 | n - dn, |
| 80 | nparam)); |
| 81 | } |
| 82 | |
| 83 | } // urls |
| 84 | } // boost |
| 85 | |
| 86 | #endif |
| 87 |
