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 103 : token_rule_t(
41 : CharSet const& cs) noexcept
42 103 : : cs_(cs)
43 : {
44 103 : }
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 :
74 : @see
75 : @ref alpha_chars,
76 : @ref parse.
77 : */
78 : template<BOOST_URL_CONSTRAINT(CharSet) CS>
79 : constexpr
80 : auto
81 103 : token_rule(
82 : CS const& cs) noexcept ->
83 : implementation_defined::token_rule_t<CS>
84 : {
85 103 : return {cs};
86 : }
87 :
88 : } // grammar
89 : } // urls
90 : } // boost
91 :
92 : #include <boost/url/grammar/impl/token_rule.hpp>
93 :
94 : #endif
|