-
Notifications
You must be signed in to change notification settings - Fork 50
/
token_rule.hpp
129 lines (105 loc) · 2.57 KB
/
token_rule.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/http_proto
//
#ifndef BOOST_URL_GRAMMAR_TOKEN_RULE_HPP
#define BOOST_URL_GRAMMAR_TOKEN_RULE_HPP
#include <boost/url/detail/config.hpp>
#include <boost/url/grammar/charset.hpp>
#include <boost/url/error_types.hpp>
#include <boost/core/detail/string_view.hpp>
namespace boost {
namespace urls {
namespace grammar {
/** Match a non-empty string of characters from a set
If there is no more input, the error code
@ref error::need_more is returned.
@par Value Type
@code
using value_type = core::string_view;
@endcode
@par Example
Rules are used with the function @ref parse.
@code
system::result< core::string_view > rv = parse( "abcdef", token_rule( alpha_chars ) );
@endcode
@par BNF
@code
token = 1*( ch )
@endcode
@param cs The character set to use
@see
@ref alpha_chars,
@ref parse.
*/
#ifdef BOOST_URL_DOCS
template<class CharSet>
constexpr
__implementation_defined__
token_rule(
CharSet cs) noexcept;
#else
namespace implementation_defined {
template<class CharSet>
struct token_rule_t
{
using value_type = core::string_view;
static_assert(
is_charset<CharSet>::value,
"CharSet requirements not met");
auto
parse(
char const*& it,
char const* end
) const noexcept ->
system::result<value_type>;
constexpr
token_rule_t(
CharSet const& cs) noexcept
: cs_(cs)
{
}
private:
CharSet const cs_;
};
}
/** Match a non-empty string of characters from a set
If there is no more input, the error code
@ref error::need_more is returned.
@par Value Type
@code
using value_type = core::string_view;
@endcode
@par Example
Rules are used with the function @ref parse.
@code
system::result< core::string_view > rv = parse( "abcdef", token_rule( alpha_chars ) );
@endcode
@par BNF
@code
token = 1*( ch )
@endcode
@param cs The character set to use
@see
@ref alpha_chars,
@ref parse.
*/
template<class CharSet>
constexpr
auto
token_rule(
CharSet const& cs) noexcept ->
implementation_defined::token_rule_t<CharSet>
{
return {cs};
}
#endif
} // grammar
} // urls
} // boost
#include <boost/url/grammar/impl/token_rule.hpp>
#endif