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 : #ifndef BOOST_URL_GRAMMAR_NOT_EMPTY_RULE_HPP
11 : #define BOOST_URL_GRAMMAR_NOT_EMPTY_RULE_HPP
12 :
13 : #include <boost/url/detail/config.hpp>
14 : #include <boost/url/error_types.hpp>
15 : #include <boost/url/grammar/type_traits.hpp>
16 :
17 : namespace boost {
18 : namespace urls {
19 : namespace grammar {
20 :
21 : namespace implementation_defined {
22 : template<class R>
23 : struct not_empty_rule_t
24 : {
25 : using value_type =
26 : typename R::value_type;
27 :
28 : auto
29 : parse(
30 : char const*& it,
31 : char const* end) const ->
32 : system::result<value_type>;
33 :
34 : constexpr
35 1 : not_empty_rule_t(
36 : R const& r) noexcept
37 1 : : r_(r)
38 : {
39 1 : }
40 :
41 : private:
42 : R r_;
43 : };
44 : } // implementation_defined
45 :
46 : /** Match another rule, if the result is not empty
47 :
48 : This adapts another rule such that
49 : when an empty string is successfully
50 : parsed, the result is an error.
51 :
52 : @par Value Type
53 : @code
54 : using value_type = typename Rule::value_type;
55 : @endcode
56 :
57 : @par Example
58 : Rules are used with the function @ref parse.
59 : @code
60 : system::result< decode_view > rv = parse( "Program%20Files",
61 : not_empty_rule( pct_encoded_rule( unreserved_chars ) ) );
62 : @endcode
63 :
64 : @param r The rule to match
65 :
66 : @see
67 : @ref parse,
68 : @ref pct_encoded_rule,
69 : @ref unreserved_chars.
70 : */
71 : template<BOOST_URL_CONSTRAINT(Rule) R>
72 : auto
73 : constexpr
74 1 : not_empty_rule(
75 : R const& r) ->
76 : implementation_defined::not_empty_rule_t<R>
77 : {
78 : // If you get a compile error here it
79 : // means that your rule does not meet
80 : // the type requirements. Please check
81 : // the documentation.
82 : static_assert(
83 : is_rule<R>::value,
84 : "Rule requirements not met");
85 :
86 1 : return { r };
87 : }
88 :
89 : } // grammar
90 : } // urls
91 : } // boost
92 :
93 : #include <boost/url/grammar/impl/not_empty_rule.hpp>
94 :
95 : #endif
|