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 +
// Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
3  
//
4  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// 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  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
7  
//
7  
// Official repository: https://github.com/boostorg/url
8  
// Official repository: https://github.com/boostorg/url
8  
//
9  
//
9  

10  

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

13  

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

18  

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

22  

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

24  

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

29  

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

34  

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

40  

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

49  

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

59  

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

62  

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

71  

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

78  

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

 
83 +
#include <boost/url/grammar/impl/literal_rule.hpp>
81  

84  

82  
#endif
85  
#endif