1 +
//
 
2 +
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
 
3 +
// Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
 
4 +
//
 
5 +
// Distributed under the Boost Software License, Version 1.0. (See accompanying
 
6 +
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
7 +
//
 
8 +
// Official repository: https://github.com/boostorg/url
 
9 +
//
 
10 +

 
11 +
#ifndef BOOST_URL_GRAMMAR_IMPL_LITERAL_RULE_HPP
 
12 +
#define BOOST_URL_GRAMMAR_IMPL_LITERAL_RULE_HPP
 
13 +

 
14 +
#include <boost/url/detail/config.hpp>
 
15 +
#include <boost/url/grammar/error.hpp>
 
16 +
#include <boost/assert.hpp>
 
17 +
#include <cstring>
 
18 +

 
19 +
namespace boost {
 
20 +
namespace urls {
 
21 +
namespace grammar {
 
22 +

 
23 +
inline BOOST_URL_CXX20_CONSTEXPR
 
24 +
auto
 
25 +
literal_rule::
 
26 +
parse(
 
27 +
    char const*& it,
 
28 +
    char const* end) const noexcept ->
 
29 +
        system::result<value_type>
 
30 +
{
 
31 +
    BOOST_ASSERT(n_ > 0);
 
32 +

 
33 +
    std::size_t n = end - it;
 
34 +
    if(n >= n_)
 
35 +
    {
 
36 +
        if(std::memcmp(
 
37 +
            it, s_, n_) != 0)
 
38 +
        {
 
39 +
            BOOST_URL_CONSTEXPR_RETURN_EC(
 
40 +
                error::mismatch);
 
41 +
        }
 
42 +
        it += n_;
 
43 +
        return core::string_view(
 
44 +
            it - n_, it);
 
45 +
    }
 
46 +
    if(n > 0)
 
47 +
    {
 
48 +
        if(std::memcmp(
 
49 +
            it, s_, n) != 0)
 
50 +
        {
 
51 +
            BOOST_URL_CONSTEXPR_RETURN_EC(
 
52 +
                error::mismatch);
 
53 +
        }
 
54 +
        BOOST_URL_CONSTEXPR_RETURN_EC(
 
55 +
            error::need_more);
 
56 +
    }
 
57 +
    BOOST_URL_CONSTEXPR_RETURN_EC(
 
58 +
        error::need_more);
 
59 +
}
 
60 +

 
61 +
} // grammar
 
62 +
} // urls
 
63 +
} // boost
 
64 +

 
65 +
#endif