Line data Source code
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 :
18 : namespace boost {
19 : namespace urls {
20 : namespace grammar {
21 :
22 : namespace implementation_defined {
23 : template<class CharSet>
24 : struct token_rule_t
25 : {
26 : using value_type = core::string_view;
27 :
28 : static_assert(
29 : is_charset<CharSet>::value,
30 : "CharSet requirements not met");
31 :
32 : auto
33 : parse(
34 : char const*& it,
35 : char const* end
36 : ) const noexcept ->
37 : system::result<value_type>;
38 :
39 : constexpr
40 71 : token_rule_t(
41 : CharSet const& cs) noexcept
42 71 : : cs_(cs)
43 : {
44 71 : }
45 :
46 : private:
47 : CharSet const cs_;
48 : };
49 : }
50 :
51 : /** Match a non-empty string of characters from a set
52 :
53 : If there is no more input, the error code
54 : @ref error::need_more is returned.
55 :
56 : @par Value Type
57 : @code
58 : using value_type = core::string_view;
59 : @endcode
60 :
61 : @par Example
62 : Rules are used with the function @ref parse.
63 : @code
64 : system::result< core::string_view > rv = parse( "abcdef", token_rule( alpha_chars ) );
65 : @endcode
66 :
67 : @par BNF
68 : @code
69 : token = 1*( ch )
70 : @endcode
71 :
72 : @param cs The character set to use
73 : @return The token rule
74 :
75 : @see
76 : @ref alpha_chars,
77 : @ref parse.
78 : */
79 : template<BOOST_URL_CONSTRAINT(CharSet) CS>
80 : constexpr
81 : auto
82 71 : token_rule(
83 : CS const& cs) noexcept ->
84 : implementation_defined::token_rule_t<CS>
85 : {
86 71 : return {cs};
87 : }
88 :
89 : } // grammar
90 : } // urls
91 : } // boost
92 :
93 : #include <boost/url/grammar/impl/token_rule.hpp>
94 :
95 : #endif
|