-
Notifications
You must be signed in to change notification settings - Fork 50
/
literal_rule.hpp
88 lines (74 loc) · 1.75 KB
/
literal_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
//
// 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/url
//
#ifndef BOOST_URL_GRAMMAR_LITERAL_RULE_HPP
#define BOOST_URL_GRAMMAR_LITERAL_RULE_HPP
#include <boost/url/detail/config.hpp>
#include <boost/url/error_types.hpp>
#include <boost/core/detail/string_view.hpp>
#include <cstdlib>
namespace boost {
namespace urls {
namespace grammar {
/** Match a string literal exactly
If there is no more input, or if the
end of the input is reached, and a prefix
of the literal matches exactly, the error
returned is @ref error::need_more.
@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( "HTTP", literal_rule( "HTTP" ) );
@endcode
@see
@ref delim_rule,
@ref parse.
*/
#ifdef BOOST_URL_DOCS
constexpr
__implementation_defined__
literal_rule( char const* s );
#else
class literal_rule
{
char const* s_ = nullptr;
std::size_t n_ = 0;
constexpr
static
std::size_t
len(char const* s) noexcept
{
return *s
? 1 + len(s + 1)
: 0;
}
public:
using value_type = core::string_view;
constexpr
explicit
literal_rule(
char const* s) noexcept
: s_(s)
, n_(len(s))
{
}
BOOST_URL_DECL
system::result<value_type>
parse(
char const*& it,
char const* end) const noexcept;
};
#endif
} // grammar
} // urls
} // boost
#endif