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_GRAMMAR_NOT_EMPTY_RULE_HPP
10  
#ifndef BOOST_URL_GRAMMAR_NOT_EMPTY_RULE_HPP
11  
#define BOOST_URL_GRAMMAR_NOT_EMPTY_RULE_HPP
11  
#define BOOST_URL_GRAMMAR_NOT_EMPTY_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/grammar/type_traits.hpp>
15  
#include <boost/url/grammar/type_traits.hpp>
16  

16  

17  
namespace boost {
17  
namespace boost {
18  
namespace urls {
18  
namespace urls {
19  
namespace grammar {
19  
namespace grammar {
20  

20  

21  
namespace implementation_defined {
21  
namespace implementation_defined {
22  
template<class R>
22  
template<class R>
23  
struct not_empty_rule_t
23  
struct not_empty_rule_t
24  
{
24  
{
25  
    using value_type =
25  
    using value_type =
26  
        typename R::value_type;
26  
        typename R::value_type;
27  

27  

28  
    auto
28  
    auto
29  
    parse(
29  
    parse(
30  
        char const*& it,
30  
        char const*& it,
31  
        char const* end) const ->
31  
        char const* end) const ->
32  
            system::result<value_type>;
32  
            system::result<value_type>;
33  

33  

34  
    constexpr
34  
    constexpr
35  
    not_empty_rule_t(
35  
    not_empty_rule_t(
36  
        R const& r) noexcept
36  
        R const& r) noexcept
37  
        : r_(r)
37  
        : r_(r)
38  
    {
38  
    {
39  
    }
39  
    }
40  

40  

41  
private:
41  
private:
42  
    R r_;
42  
    R r_;
43  
};
43  
};
44  
} // implementation_defined
44  
} // implementation_defined
45  

45  

46  
/** Match another rule, if the result is not empty
46  
/** Match another rule, if the result is not empty
47  

47  

48  
    This adapts another rule such that
48  
    This adapts another rule such that
49  
    when an empty string is successfully
49  
    when an empty string is successfully
50  
    parsed, the result is an error.
50  
    parsed, the result is an error.
51  

51  

52  
    @par Value Type
52  
    @par Value Type
53  
    @code
53  
    @code
54  
    using value_type = typename Rule::value_type;
54  
    using value_type = typename Rule::value_type;
55  
    @endcode
55  
    @endcode
56  

56  

57  
    @par Example
57  
    @par Example
58  
    Rules are used with the function @ref parse.
58  
    Rules are used with the function @ref parse.
59  
    @code
59  
    @code
60  
    system::result< decode_view > rv = parse( "Program%20Files",
60  
    system::result< decode_view > rv = parse( "Program%20Files",
61  
        not_empty_rule( pct_encoded_rule( unreserved_chars ) ) );
61  
        not_empty_rule( pct_encoded_rule( unreserved_chars ) ) );
62  
    @endcode
62  
    @endcode
63  

63  

64  
    @param r The rule to match
64  
    @param r The rule to match
65  
    @return The adapted rule
65  
    @return The adapted rule
66  

66  

67  
    @see
67  
    @see
68  
        @ref parse,
68  
        @ref parse,
69  
        @ref pct_encoded_rule,
69  
        @ref pct_encoded_rule,
70  
        @ref unreserved_chars.
70  
        @ref unreserved_chars.
71  
*/
71  
*/
72  
template<BOOST_URL_CONSTRAINT(Rule) R>
72  
template<BOOST_URL_CONSTRAINT(Rule) R>
73  
auto
73  
auto
74  
constexpr
74  
constexpr
75  
not_empty_rule(
75  
not_empty_rule(
76  
    R const& r) ->
76  
    R const& r) ->
77  
        implementation_defined::not_empty_rule_t<R>
77  
        implementation_defined::not_empty_rule_t<R>
78  
{
78  
{
79  
    // If you get a compile error here it
79  
    // If you get a compile error here it
80  
    // means that your rule does not meet
80  
    // means that your rule does not meet
81  
    // the type requirements. Please check
81  
    // the type requirements. Please check
82  
    // the documentation.
82  
    // the documentation.
83  
    static_assert(
83  
    static_assert(
84  
        is_rule<R>::value,
84  
        is_rule<R>::value,
85  
        "Rule requirements not met");
85  
        "Rule requirements not met");
86  

86  

87  
    return { r };
87  
    return { r };
88  
}
88  
}
89  

89  

90  
} // grammar
90  
} // grammar
91  
} // urls
91  
} // urls
92  
} // boost
92  
} // boost
93  

93  

94  
#include <boost/url/grammar/impl/not_empty_rule.hpp>
94  
#include <boost/url/grammar/impl/not_empty_rule.hpp>
95  

95  

96  
#endif
96  
#endif