include/boost/url/rfc/detail/impl/scheme_rule.hpp

100.0% Lines (14/14) 100.0% Functions (1/1) 100.0% Branches (4/4)
include/boost/url/rfc/detail/impl/scheme_rule.hpp
Line Branch Hits Source Code
1 //
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot 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_RFC_DETAIL_IMPL_SCHEME_RULE_HPP
12 #define BOOST_URL_RFC_DETAIL_IMPL_SCHEME_RULE_HPP
13
14 #include <boost/url/detail/config.hpp>
15 #include <boost/url/grammar/alpha_chars.hpp>
16 #include <boost/url/grammar/charset.hpp>
17 #include <boost/url/grammar/error.hpp>
18 #include <boost/url/grammar/lut_chars.hpp>
19 #include <boost/url/grammar/parse.hpp>
20
21 namespace boost {
22 namespace urls {
23 namespace detail {
24
25 inline BOOST_URL_CXX20_CONSTEXPR
26 auto
27 3737 scheme_rule::
28 parse(
29 char const*& it,
30 char const* end) const noexcept ->
31 system::result<value_type>
32 {
33 3737 auto const start = it;
34
2/2
✓ Branch 0 taken 124 times.
✓ Branch 1 taken 3613 times.
3737 if(it == end)
35 {
36 124 BOOST_URL_CONSTEXPR_RETURN_EC(
37 grammar::error::mismatch);
38 }
39
2/2
✓ Branch 1 taken 850 times.
✓ Branch 2 taken 2763 times.
3613 if(! grammar::alpha_chars(*it))
40 {
41 850 BOOST_URL_CONSTEXPR_RETURN_EC(
42 grammar::error::mismatch);
43 }
44
45 constexpr
46 2763 grammar::lut_chars scheme_chars(
47 "0123456789" "+-."
48 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
49 "abcdefghijklmnopqrstuvwxyz");
50 5526 it = grammar::find_if_not(
51 2763 it + 1, end, scheme_chars);
52 2763 value_type t;
53 5526 t.scheme = core::string_view(
54 2763 start, it - start);
55 2763 t.scheme_id = string_to_scheme(
56 t.scheme);
57 2763 return t;
58 }
59
60 } // detail
61 } // urls
62 } // boost
63
64
65 #endif
66