1  
//
1  
//
2  
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
2  
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3  
//
3  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
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)
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
6  
//
7  
// Official repository: https://github.com/boostorg/url
7  
// Official repository: https://github.com/boostorg/url
8  
//
8  
//
9  

9  

10  
#ifndef BOOST_URL_GRAMMAR_LITERAL_RULE_HPP
10  
#ifndef BOOST_URL_GRAMMAR_LITERAL_RULE_HPP
11  
#define BOOST_URL_GRAMMAR_LITERAL_RULE_HPP
11  
#define BOOST_URL_GRAMMAR_LITERAL_RULE_HPP
12  

12  

13  
#include <boost/url/detail/config.hpp>
13  
#include <boost/url/detail/config.hpp>
14  
#include <boost/url/error_types.hpp>
14  
#include <boost/url/error_types.hpp>
15  
#include <boost/core/detail/string_view.hpp>
15  
#include <boost/core/detail/string_view.hpp>
16  
#include <cstdlib>
16  
#include <cstdlib>
17  

17  

18  
namespace boost {
18  
namespace boost {
19  
namespace urls {
19  
namespace urls {
20  
namespace grammar {
20  
namespace grammar {
21  

21  

22  
/** Match a string literal exactly
22  
/** Match a string literal exactly
23  

23  

24  
    If there is no more input, or if the
24  
    If there is no more input, or if the
25  
    end of the input is reached, and a prefix
25  
    end of the input is reached, and a prefix
26  
    of the literal matches exactly, the error
26  
    of the literal matches exactly, the error
27  
    returned is @ref error::need_more.
27  
    returned is @ref error::need_more.
28  

28  

29  
    @par Value Type
29  
    @par Value Type
30  
    @code
30  
    @code
31  
    using value_type = core::string_view;
31  
    using value_type = core::string_view;
32  
    @endcode
32  
    @endcode
33  

33  

34  
    @par Example
34  
    @par Example
35  
    Rules are used with the function @ref parse.
35  
    Rules are used with the function @ref parse.
36  
    @code
36  
    @code
37  
    system::result< core::string_view > rv = parse( "HTTP", literal_rule( "HTTP" ) );
37  
    system::result< core::string_view > rv = parse( "HTTP", literal_rule( "HTTP" ) );
38  
    @endcode
38  
    @endcode
39  

39  

40  
    @see
40  
    @see
41  
        @ref delim_rule,
41  
        @ref delim_rule,
42  
        @ref parse.
42  
        @ref parse.
43  
*/
43  
*/
44  
class literal_rule
44  
class literal_rule
45  
{
45  
{
46  
    char const* s_ = nullptr;
46  
    char const* s_ = nullptr;
47  
    std::size_t n_ = 0;
47  
    std::size_t n_ = 0;
48  

48  

49  
    constexpr
49  
    constexpr
50  
    static
50  
    static
51  
    std::size_t
51  
    std::size_t
52  
    len(char const* s) noexcept
52  
    len(char const* s) noexcept
53  
    {
53  
    {
54  
        return *s
54  
        return *s
55  
            ? 1 + len(s + 1)
55  
            ? 1 + len(s + 1)
56  
            : 0;
56  
            : 0;
57  
    }
57  
    }
58  

58  

59  
public:
59  
public:
60  
    using value_type = core::string_view;
60  
    using value_type = core::string_view;
61  

61  

62  
    constexpr
62  
    constexpr
63  
    explicit
63  
    explicit
64  
    literal_rule(
64  
    literal_rule(
65  
        char const* s) noexcept
65  
        char const* s) noexcept
66  
        : s_(s)
66  
        : s_(s)
67  
        , n_(len(s))
67  
        , n_(len(s))
68  
    {
68  
    {
69  
    }
69  
    }
70  

70  

71  
    BOOST_URL_DECL
71  
    BOOST_URL_DECL
72  
    system::result<value_type>
72  
    system::result<value_type>
73  
    parse(
73  
    parse(
74  
        char const*& it,
74  
        char const*& it,
75  
        char const* end) const noexcept;
75  
        char const* end) const noexcept;
76  
};
76  
};
77  

77  

78  
} // grammar
78  
} // grammar
79  
} // urls
79  
} // urls
80  
} // boost
80  
} // boost
81  

81  

82  
#endif
82  
#endif