100.00% Lines (16/16) 100.00% Functions (1/1)
TLA Baseline Branch
Line Hits Code Line Hits Code
1   // 1   //
2   // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) 2   // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3   // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com) 3   // Copyright (c) 2023 Alan de Freitas (alandefreitas@gmail.com)
4   // 4   //
5   // Distributed under the Boost Software License, Version 1.0. (See accompanying 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) 6   // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7   // 7   //
8   // Official repository: https://github.com/boostorg/url 8   // Official repository: https://github.com/boostorg/url
9   // 9   //
10   10  
11   #ifndef BOOST_URL_GRAMMAR_IMPL_LITERAL_RULE_HPP 11   #ifndef BOOST_URL_GRAMMAR_IMPL_LITERAL_RULE_HPP
12   #define BOOST_URL_GRAMMAR_IMPL_LITERAL_RULE_HPP 12   #define BOOST_URL_GRAMMAR_IMPL_LITERAL_RULE_HPP
13   13  
14   #include <boost/url/detail/config.hpp> 14   #include <boost/url/detail/config.hpp>
15   #include <boost/url/grammar/error.hpp> 15   #include <boost/url/grammar/error.hpp>
16   #include <boost/assert.hpp> 16   #include <boost/assert.hpp>
17   #include <cstring> 17   #include <cstring>
18   18  
19   namespace boost { 19   namespace boost {
20   namespace urls { 20   namespace urls {
21   namespace grammar { 21   namespace grammar {
22   22  
23   BOOST_URL_CXX20_CONSTEXPR_OR_INLINE 23   BOOST_URL_CXX20_CONSTEXPR_OR_INLINE
24   auto 24   auto
HITCBC 25   10 literal_rule:: 25   10 literal_rule::
26   parse( 26   parse(
27   char const*& it, 27   char const*& it,
28   char const* end) const noexcept -> 28   char const* end) const noexcept ->
29   system::result<value_type> 29   system::result<value_type>
30   { 30   {
31   // Can't have a literal 31   // Can't have a literal
32   // with an empty string! 32   // with an empty string!
HITCBC 33   10 BOOST_ASSERT(n_ > 0); 33   10 BOOST_ASSERT(n_ > 0);
34   34  
HITCBC 35   10 std::size_t n = end - it; 35   10 std::size_t n = end - it;
HITCBC 36   10 if(n >= n_) 36   10 if(n >= n_)
37   { 37   {
HITCBC 38   4 if(std::memcmp( 38   4 if(std::memcmp(
HITCBC 39   4 it, s_, n_) != 0) 39   4 it, s_, n_) != 0)
40   { 40   {
41   // non-match 41   // non-match
HITCBC 42   1 BOOST_URL_CONSTEXPR_RETURN_EC( 42   1 BOOST_URL_CONSTEXPR_RETURN_EC(
43   error::mismatch); 43   error::mismatch);
44   } 44   }
HITCBC 45   3 it += n_; 45   3 it += n_;
HITCBC 46   3 return core::string_view( 46   3 return core::string_view(
HITCBC 47   3 it - n_, it); 47   3 it - n_, it);
48   } 48   }
HITCBC 49   6 if(n > 0) 49   6 if(n > 0)
50   { 50   {
51   // short input 51   // short input
HITCBC 52   5 if(std::memcmp( 52   5 if(std::memcmp(
HITCBC 53   5 it, s_, n) != 0) 53   5 it, s_, n) != 0)
54   { 54   {
55   // non-match 55   // non-match
HITCBC 56   2 BOOST_URL_CONSTEXPR_RETURN_EC( 56   2 BOOST_URL_CONSTEXPR_RETURN_EC(
57   error::mismatch); 57   error::mismatch);
58   } 58   }
59   // prefix matches 59   // prefix matches
HITCBC 60   3 BOOST_URL_CONSTEXPR_RETURN_EC( 60   3 BOOST_URL_CONSTEXPR_RETURN_EC(
61   error::need_more); 61   error::need_more);
62   } 62   }
63   // end 63   // end
HITCBC 64   1 BOOST_URL_CONSTEXPR_RETURN_EC( 64   1 BOOST_URL_CONSTEXPR_RETURN_EC(
65   error::need_more); 65   error::need_more);
66   } 66   }
67   67  
68   } // grammar 68   } // grammar
69   } // urls 69   } // urls
70   } // boost 70   } // boost
71   71  
72   #endif 72   #endif