| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | @return The adapted rule | ||
| 66 | |||
| 67 | @see | ||
| 68 | @ref parse, | ||
| 69 | @ref pct_encoded_rule, | ||
| 70 | @ref unreserved_chars. | ||
| 71 | */ | ||
| 72 | template<BOOST_URL_CONSTRAINT(Rule) R> | ||
| 73 | auto | ||
| 74 | constexpr | ||
| 75 | 1 | not_empty_rule( | |
| 76 | R const& r) -> | ||
| 77 | implementation_defined::not_empty_rule_t<R> | ||
| 78 | { | ||
| 79 | // If you get a compile error here it | ||
| 80 | // means that your rule does not meet | ||
| 81 | // the type requirements. Please check | ||
| 82 | // the documentation. | ||
| 83 | static_assert( | ||
| 84 | is_rule<R>::value, | ||
| 85 | "Rule requirements not met"); | ||
| 86 | |||
| 87 | 1 | return { r }; | |
| 88 | } | ||
| 89 | |||
| 90 | } // grammar | ||
| 91 | } // urls | ||
| 92 | } // boost | ||
| 93 | |||
| 94 | #include <boost/url/grammar/impl/not_empty_rule.hpp> | ||
| 95 | |||
| 96 | #endif | ||
| 97 |