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