GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 37 / 0 / 37
Functions: 100.0% 14 / 0 / 14
Branches: -% 0 / 0 / 0

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