1  
//
1  
//
2  
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
2  
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3  
//
3  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
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)
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
6  
//
7  
// Official repository: https://github.com/boostorg/url
7  
// Official repository: https://github.com/boostorg/url
8  
//
8  
//
9  

9  

10  
#ifndef BOOST_URL_RFC_DETAIL_QUERY_PART_RULE_HPP
10  
#ifndef BOOST_URL_RFC_DETAIL_QUERY_PART_RULE_HPP
11  
#define BOOST_URL_RFC_DETAIL_QUERY_PART_RULE_HPP
11  
#define BOOST_URL_RFC_DETAIL_QUERY_PART_RULE_HPP
12  

12  

13  
#include "boost/url/detail/config.hpp"
13  
#include "boost/url/detail/config.hpp"
14  
#include "boost/url/error_types.hpp"
14  
#include "boost/url/error_types.hpp"
15  
#include "boost/url/pct_string_view.hpp"
15  
#include "boost/url/pct_string_view.hpp"
16  
#include "boost/url/rfc/query_rule.hpp"
16  
#include "boost/url/rfc/query_rule.hpp"
17  
#include "boost/url/grammar/parse.hpp"
17  
#include "boost/url/grammar/parse.hpp"
18  
#include <cstdlib>
18  
#include <cstdlib>
19  

19  

20  
namespace boost {
20  
namespace boost {
21  
namespace urls {
21  
namespace urls {
22  
namespace detail {
22  
namespace detail {
23  

23  

24  
/** Rule for query-part
24  
/** Rule for query-part
25  

25  

26  
    @par BNF
26  
    @par BNF
27  
    @code
27  
    @code
28  
    query-part    = [ "?" query ]
28  
    query-part    = [ "?" query ]
29  
    @endcode
29  
    @endcode
30  
*/
30  
*/
31  
struct query_part_rule_t
31  
struct query_part_rule_t
32  
{
32  
{
33  
    struct value_type
33  
    struct value_type
34  
    {
34  
    {
35  
        pct_string_view query;
35  
        pct_string_view query;
36  
        std::size_t count = 0;
36  
        std::size_t count = 0;
37  
        bool has_query = false;
37  
        bool has_query = false;
38  
    };
38  
    };
39  

39  

40  
    auto
40  
    auto
41  
    parse(
41  
    parse(
42  
        char const*& it,
42  
        char const*& it,
43  
        char const* end
43  
        char const* end
44  
            ) const noexcept ->
44  
            ) const noexcept ->
45  
        system::result<value_type>
45  
        system::result<value_type>
46  
    {
46  
    {
47  
        if( it == end ||
47  
        if( it == end ||
48  
            *it != '?')
48  
            *it != '?')
49  
            return {};
49  
            return {};
50  
        ++it;
50  
        ++it;
51  
        auto rv = grammar::parse(
51  
        auto rv = grammar::parse(
52  
            it, end, query_rule);
52  
            it, end, query_rule);
53  
        // query_rule is optionally empty and must not fail
53  
        // query_rule is optionally empty and must not fail
54  
        BOOST_ASSERT( rv );
54  
        BOOST_ASSERT( rv );
55  
        value_type t;
55  
        value_type t;
56  
        t.query = rv->buffer();
56  
        t.query = rv->buffer();
57  
        t.count = rv->size();
57  
        t.count = rv->size();
58  
        // a query_rule represents at least one parameter:
58  
        // a query_rule represents at least one parameter:
59  
        // <empty key, no value>
59  
        // <empty key, no value>
60  
        BOOST_ASSERT( t.count );
60  
        BOOST_ASSERT( t.count );
61  
        t.has_query = true;
61  
        t.has_query = true;
62  
        return t;
62  
        return t;
63  
    }
63  
    }
64  
};
64  
};
65  

65  

66  
constexpr query_part_rule_t query_part_rule{};
66  
constexpr query_part_rule_t query_part_rule{};
67  

67  

68  
} // detail
68  
} // detail
69  
} // urls
69  
} // urls
70  
} // boost
70  
} // boost
71  

71  

72  
#endif
72  
#endif