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 +
// Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
3  
//
4  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// 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  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
7  
//
7  
// Official repository: https://github.com/boostorg/url
8  
// Official repository: https://github.com/boostorg/url
8  
//
9  
//
9  

10  

10  
#ifndef BOOST_URL_GRAMMAR_NOT_EMPTY_RULE_HPP
11  
#ifndef BOOST_URL_GRAMMAR_NOT_EMPTY_RULE_HPP
11  
#define BOOST_URL_GRAMMAR_NOT_EMPTY_RULE_HPP
12  
#define BOOST_URL_GRAMMAR_NOT_EMPTY_RULE_HPP
12  

13  

13  
#include <boost/url/detail/config.hpp>
14  
#include <boost/url/detail/config.hpp>
14  
#include <boost/url/error_types.hpp>
15  
#include <boost/url/error_types.hpp>
15  
#include <boost/url/grammar/type_traits.hpp>
16  
#include <boost/url/grammar/type_traits.hpp>
16  

17  

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

21  

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

28  

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

35  

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

42  

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

47  

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

49  

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

53  

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

58  

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

65  

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

68  

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

88  

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

91  

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

95  

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

97  

96  
#endif
98  
#endif