100.00% Lines (8/8) 100.00% Functions (2/2)
TLA Baseline Branch
Line Hits Code Line Hits Code
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   // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com) 3   // Copyright (c) 2022 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_LITERAL_RULE_HPP 11   #ifndef BOOST_URL_GRAMMAR_LITERAL_RULE_HPP
12   #define BOOST_URL_GRAMMAR_LITERAL_RULE_HPP 12   #define BOOST_URL_GRAMMAR_LITERAL_RULE_HPP
13   13  
14   #include <boost/url/detail/config.hpp> 14   #include <boost/url/detail/config.hpp>
15   #include <boost/url/error_types.hpp> 15   #include <boost/url/error_types.hpp>
16   #include <boost/core/detail/string_view.hpp> 16   #include <boost/core/detail/string_view.hpp>
17   #include <cstdlib> 17   #include <cstdlib>
18   18  
19   namespace boost { 19   namespace boost {
20   namespace urls { 20   namespace urls {
21   namespace grammar { 21   namespace grammar {
22   22  
23   /** Match a string literal exactly 23   /** Match a string literal exactly
24   24  
25   If there is no more input, or if the 25   If there is no more input, or if the
26   end of the input is reached, and a prefix 26   end of the input is reached, and a prefix
27   of the literal matches exactly, the error 27   of the literal matches exactly, the error
28   returned is @ref error::need_more. 28   returned is @ref error::need_more.
29   29  
30   @par Value Type 30   @par Value Type
31   @code 31   @code
32   using value_type = core::string_view; 32   using value_type = core::string_view;
33   @endcode 33   @endcode
34   34  
35   @par Example 35   @par Example
36   Rules are used with the function @ref parse. 36   Rules are used with the function @ref parse.
37   @code 37   @code
38   system::result< core::string_view > rv = parse( "HTTP", literal_rule( "HTTP" ) ); 38   system::result< core::string_view > rv = parse( "HTTP", literal_rule( "HTTP" ) );
39   @endcode 39   @endcode
40   40  
41   @see 41   @see
42   @ref delim_rule, 42   @ref delim_rule,
43   @ref parse. 43   @ref parse.
44   */ 44   */
45   class literal_rule 45   class literal_rule
46   { 46   {
47   char const* s_ = nullptr; 47   char const* s_ = nullptr;
48   std::size_t n_ = 0; 48   std::size_t n_ = 0;
49   49  
50   constexpr 50   constexpr
51   static 51   static
52   std::size_t 52   std::size_t
HITCBC 53   48 len(char const* s) noexcept 53   48 len(char const* s) noexcept
54   { 54   {
HITCBC 55   48 return *s 55   48 return *s
HITCBC 56   48 ? 1 + len(s + 1) 56   48 ? 1 + len(s + 1)
HITCBC 57   48 : 0; 57   48 : 0;
58   } 58   }
59   59  
60   public: 60   public:
61   using value_type = core::string_view; 61   using value_type = core::string_view;
62   62  
63   constexpr 63   constexpr
64   explicit 64   explicit
HITCBC 65   10 literal_rule( 65   10 literal_rule(
66   char const* s) noexcept 66   char const* s) noexcept
HITCBC 67   10 : s_(s) 67   10 : s_(s)
HITCBC 68   10 , n_(len(s)) 68   10 , n_(len(s))
69   { 69   {
HITCBC 70   10 } 70   10 }
71   71  
72   BOOST_URL_CXX20_CONSTEXPR 72   BOOST_URL_CXX20_CONSTEXPR
73   system::result<value_type> 73   system::result<value_type>
74   parse( 74   parse(
75   char const*& it, 75   char const*& it,
76   char const* end) const noexcept; 76   char const* end) const noexcept;
77   }; 77   };
78   78  
79   } // grammar 79   } // grammar
80   } // urls 80   } // urls
81   } // boost 81   } // boost
82   82  
83   #include <boost/url/grammar/impl/literal_rule.hpp> 83   #include <boost/url/grammar/impl/literal_rule.hpp>
84   84  
85   #endif 85   #endif