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  

10  

11  
#include <boost/url/detail/config.hpp>
11  
#include <boost/url/detail/config.hpp>
12  
#include "scheme_rule.hpp"
12  
#include "scheme_rule.hpp"
13  
#include <boost/url/grammar/alpha_chars.hpp>
13  
#include <boost/url/grammar/alpha_chars.hpp>
14  
#include <boost/url/grammar/delim_rule.hpp>
14  
#include <boost/url/grammar/delim_rule.hpp>
15  
#include <boost/url/grammar/lut_chars.hpp>
15  
#include <boost/url/grammar/lut_chars.hpp>
16  
#include <boost/url/grammar/parse.hpp>
16  
#include <boost/url/grammar/parse.hpp>
17  
#include <boost/url/grammar/tuple_rule.hpp>
17  
#include <boost/url/grammar/tuple_rule.hpp>
18  

18  

19  
namespace boost {
19  
namespace boost {
20  
namespace urls {
20  
namespace urls {
21  
namespace detail {
21  
namespace detail {
22  

22  

23  
auto
23  
auto
24  
scheme_rule::
24  
scheme_rule::
25  
parse(
25  
parse(
26  
    char const*& it,
26  
    char const*& it,
27  
    char const* end) const noexcept ->
27  
    char const* end) const noexcept ->
28  
        system::result<value_type>
28  
        system::result<value_type>
29  
{
29  
{
30  
    auto const start = it;
30  
    auto const start = it;
31  
    if(it == end)
31  
    if(it == end)
32  
    {
32  
    {
33  
        // end
33  
        // end
34  
        BOOST_URL_RETURN_EC(
34  
        BOOST_URL_RETURN_EC(
35  
            grammar::error::mismatch);
35  
            grammar::error::mismatch);
36  
    }
36  
    }
37  
    if(! grammar::alpha_chars(*it))
37  
    if(! grammar::alpha_chars(*it))
38  
    {
38  
    {
39  
        // expected alpha
39  
        // expected alpha
40  
        BOOST_URL_RETURN_EC(
40  
        BOOST_URL_RETURN_EC(
41  
            grammar::error::mismatch);
41  
            grammar::error::mismatch);
42  
    }
42  
    }
43  

43  

44  
    static
44  
    static
45  
    constexpr
45  
    constexpr
46  
    grammar::lut_chars scheme_chars(
46  
    grammar::lut_chars scheme_chars(
47  
        "0123456789" "+-."
47  
        "0123456789" "+-."
48  
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
48  
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
49  
        "abcdefghijklmnopqrstuvwxyz");
49  
        "abcdefghijklmnopqrstuvwxyz");
50  
    it = grammar::find_if_not(
50  
    it = grammar::find_if_not(
51  
        it + 1, end, scheme_chars);
51  
        it + 1, end, scheme_chars);
52  
    value_type t;
52  
    value_type t;
53  
    t.scheme = core::string_view(
53  
    t.scheme = core::string_view(
54  
        start, it - start);
54  
        start, it - start);
55  
    t.scheme_id = string_to_scheme(
55  
    t.scheme_id = string_to_scheme(
56  
        t.scheme);
56  
        t.scheme);
57  
    return t;
57  
    return t;
58  
}
58  
}
59  

59  

60  
} // detail
60  
} // detail
61  
} // urls
61  
} // urls
62  
} // boost
62  
} // boost
63  

63