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/http_proto 8   // Official repository: https://github.com/boostorg/http_proto
9   // 9   //
10   10  
11   #ifndef BOOST_URL_GRAMMAR_TOKEN_RULE_HPP 11   #ifndef BOOST_URL_GRAMMAR_TOKEN_RULE_HPP
12   #define BOOST_URL_GRAMMAR_TOKEN_RULE_HPP 12   #define BOOST_URL_GRAMMAR_TOKEN_RULE_HPP
13   13  
14   #include <boost/url/detail/config.hpp> 14   #include <boost/url/detail/config.hpp>
15   #include <boost/url/grammar/charset.hpp> 15   #include <boost/url/grammar/charset.hpp>
16   #include <boost/url/error_types.hpp> 16   #include <boost/url/error_types.hpp>
17   #include <boost/core/detail/string_view.hpp> 17   #include <boost/core/detail/string_view.hpp>
18   #include <boost/core/empty_value.hpp> 18   #include <boost/core/empty_value.hpp>
19   #include <type_traits> 19   #include <type_traits>
20   20  
21   namespace boost { 21   namespace boost {
22   namespace urls { 22   namespace urls {
23   namespace grammar { 23   namespace grammar {
24   24  
25   namespace implementation_defined { 25   namespace implementation_defined {
26   template<class CharSet> 26   template<class CharSet>
27   struct token_rule_t 27   struct token_rule_t
28   : private empty_value<CharSet> 28   : private empty_value<CharSet>
29   { 29   {
30   using value_type = core::string_view; 30   using value_type = core::string_view;
31   31  
32   static_assert( 32   static_assert(
33   is_charset<CharSet>::value, 33   is_charset<CharSet>::value,
34   "CharSet requirements not met"); 34   "CharSet requirements not met");
35   35  
36   BOOST_URL_CXX20_CONSTEXPR 36   BOOST_URL_CXX20_CONSTEXPR
37   auto 37   auto
38   parse( 38   parse(
39   char const*& it, 39   char const*& it,
40   char const* end 40   char const* end
41   ) const noexcept -> 41   ) const noexcept ->
42   system::result<value_type>; 42   system::result<value_type>;
43   43  
44   constexpr 44   constexpr
HITCBC 45   79 token_rule_t( 45   79 token_rule_t(
46   CharSet const& cs) noexcept 46   CharSet const& cs) noexcept
47   : empty_value<CharSet>( 47   : empty_value<CharSet>(
HITCBC 48   79 empty_init, cs) 48   79 empty_init, cs)
49   { 49   {
HITCBC 50   79 } 50   79 }
51   51  
52   template<class CS = CharSet> 52   template<class CS = CharSet>
53   constexpr 53   constexpr
54   token_rule_t( 54   token_rule_t(
55   typename std::enable_if< 55   typename std::enable_if<
56   std::is_default_constructible<CS>::value, 56   std::is_default_constructible<CS>::value,
57   int>::type = 0) noexcept 57   int>::type = 0) noexcept
58   : empty_value<CharSet>( 58   : empty_value<CharSet>(
59   empty_init) 59   empty_init)
60   { 60   {
61   } 61   }
62   }; 62   };
63   } 63   }
64   64  
65   /** Match a non-empty string of characters from a set 65   /** Match a non-empty string of characters from a set
66   66  
67   If there is no more input, the error code 67   If there is no more input, the error code
68   @ref error::need_more is returned. 68   @ref error::need_more is returned.
69   69  
70   @par Value Type 70   @par Value Type
71   @code 71   @code
72   using value_type = core::string_view; 72   using value_type = core::string_view;
73   @endcode 73   @endcode
74   74  
75   @par Example 75   @par Example
76   Rules are used with the function @ref parse. 76   Rules are used with the function @ref parse.
77   @code 77   @code
78   system::result< core::string_view > rv = parse( "abcdef", token_rule( alpha_chars ) ); 78   system::result< core::string_view > rv = parse( "abcdef", token_rule( alpha_chars ) );
79   @endcode 79   @endcode
80   80  
81   @par BNF 81   @par BNF
82   @code 82   @code
83   token = 1*( ch ) 83   token = 1*( ch )
84   @endcode 84   @endcode
85   85  
86   @param cs The character set to use 86   @param cs The character set to use
87   @return The token rule 87   @return The token rule
88   88  
89   @see 89   @see
90   @ref alpha_chars, 90   @ref alpha_chars,
91   @ref parse. 91   @ref parse.
92   */ 92   */
93   template<BOOST_URL_CONSTRAINT(CharSet) CS> 93   template<BOOST_URL_CONSTRAINT(CharSet) CS>
94   constexpr 94   constexpr
95   auto 95   auto
HITCBC 96   79 token_rule( 96   79 token_rule(
97   CS const& cs) noexcept -> 97   CS const& cs) noexcept ->
98   implementation_defined::token_rule_t<CS> 98   implementation_defined::token_rule_t<CS>
99   { 99   {
HITCBC 100   79 return {cs}; 100   79 return {cs};
101   } 101   }
102   102  
103   /** Match a non-empty string of characters from a default-constructible set 103   /** Match a non-empty string of characters from a default-constructible set
104   104  
105   This overload is only available when CharSet is 105   This overload is only available when CharSet is
106   default constructible. 106   default constructible.
107   107  
108   If there is no more input, the error code 108   If there is no more input, the error code
109   @ref error::need_more is returned. 109   @ref error::need_more is returned.
110   110  
111   @par Value Type 111   @par Value Type
112   @code 112   @code
113   using value_type = core::string_view; 113   using value_type = core::string_view;
114   @endcode 114   @endcode
115   115  
116   @par Example 116   @par Example
117   Rules are used with the function @ref parse. 117   Rules are used with the function @ref parse.
118   @code 118   @code
119   system::result< core::string_view > rv = parse( "abcdef", token_rule<alpha_chars_t>() ); 119   system::result< core::string_view > rv = parse( "abcdef", token_rule<alpha_chars_t>() );
120   @endcode 120   @endcode
121   121  
122   @par BNF 122   @par BNF
123   @code 123   @code
124   token = 1*( ch ) 124   token = 1*( ch )
125   @endcode 125   @endcode
126   126  
127   @tparam CharSet The character set type to use 127   @tparam CharSet The character set type to use
128   @return The token rule 128   @return The token rule
129   129  
130   @see 130   @see
131   @ref alpha_chars, 131   @ref alpha_chars,
132   @ref parse. 132   @ref parse.
133   */ 133   */
134   template<BOOST_URL_CONSTRAINT(CharSet) CharSet> 134   template<BOOST_URL_CONSTRAINT(CharSet) CharSet>
135   constexpr 135   constexpr
136   auto 136   auto
137   token_rule() noexcept -> 137   token_rule() noexcept ->
138   typename std::enable_if< 138   typename std::enable_if<
139   std::is_default_constructible<CharSet>::value, 139   std::is_default_constructible<CharSet>::value,
140   implementation_defined::token_rule_t<CharSet>>::type 140   implementation_defined::token_rule_t<CharSet>>::type
141   { 141   {
142   return implementation_defined::token_rule_t<CharSet>(); 142   return implementation_defined::token_rule_t<CharSet>();
143   } 143   }
144   144  
145   } // grammar 145   } // grammar
146   } // urls 146   } // urls
147   } // boost 147   } // boost
148   148  
149   #include <boost/url/grammar/impl/token_rule.hpp> 149   #include <boost/url/grammar/impl/token_rule.hpp>
150   150  
151   #endif 151   #endif