1 -

 
2 -
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.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/url
 
8 -
//
 
9 -

 
10 -

 
11 -
#include <boost/url/detail/config.hpp>
 
12 -
#include <boost/url/grammar/error.hpp>
 
13 -
#include <boost/url/grammar/literal_rule.hpp>
 
14 -
#include <boost/assert.hpp>
 
15 -
#include <cstring>
 
16 -

 
17 -
namespace boost {
 
18 -
namespace urls {
 
19 -
namespace grammar {
 
20 -

 
21 -
auto
 
22 -
literal_rule::
 
23 -
parse(
 
24 -
    char const*& it,
 
25 -
    char const* end) const noexcept ->
 
26 -
        system::result<value_type>
 
27 -
{
 
28 -
    // Can't have a literal
 
29 -
    // with an empty string!
 
30 -
    BOOST_ASSERT(n_ > 0);
 
31 -

 
32 -
    std::size_t n = end - it;
 
33 -
    if(n >= n_)
 
34 -
    {
 
35 -
        if(std::memcmp(
 
36 -
            it, s_, n_) != 0)
 
37 -
        {
 
38 -
            // non-match
 
39 -
            BOOST_URL_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 -
        // short input
 
49 -
        if(std::memcmp(
 
50 -
            it, s_, n) != 0)
 
51 -
        {
 
52 -
            // non-match
 
53 -
            BOOST_URL_RETURN_EC(
 
54 -
                error::mismatch);
 
55 -
        }
 
56 -
        // prefix matches
 
57 -
        BOOST_URL_RETURN_EC(
 
58 -
            error::need_more);
 
59 -
    }
 
60 -
    // end
 
61 -
    BOOST_URL_RETURN_EC(
 
62 -
        error::need_more);
 
63 -
}
 
64 -

 
65 -
} // grammar
 
66 -
} // urls
 
67 -
} // boost
 
68 -