Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:52:40

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/url
0008 //
0009 
0010 #ifndef BOOST_URL_GRAMMAR_LITERAL_RULE_HPP
0011 #define BOOST_URL_GRAMMAR_LITERAL_RULE_HPP
0012 
0013 #include <boost/url/detail/config.hpp>
0014 #include <boost/url/error_types.hpp>
0015 #include <boost/core/detail/string_view.hpp>
0016 #include <cstdlib>
0017 
0018 namespace boost {
0019 namespace urls {
0020 namespace grammar {
0021 
0022 /** Match a string literal exactly
0023 
0024     If there is no more input, or if the
0025     end of the input is reached, and a prefix
0026     of the literal matches exactly, the error
0027     returned is @ref error::need_more.
0028 
0029     @par Value Type
0030     @code
0031     using value_type = core::string_view;
0032     @endcode
0033 
0034     @par Example
0035     Rules are used with the function @ref parse.
0036     @code
0037     system::result< core::string_view > rv = parse( "HTTP", literal_rule( "HTTP" ) );
0038     @endcode
0039 
0040     @see
0041         @ref delim_rule,
0042         @ref parse.
0043 */
0044 class literal_rule
0045 {
0046     char const* s_ = nullptr;
0047     std::size_t n_ = 0;
0048 
0049     constexpr
0050     static
0051     std::size_t
0052     len(char const* s) noexcept
0053     {
0054         return *s
0055             ? 1 + len(s + 1)
0056             : 0;
0057     }
0058 
0059 public:
0060     using value_type = core::string_view;
0061 
0062     constexpr
0063     explicit
0064     literal_rule(
0065         char const* s) noexcept
0066         : s_(s)
0067         , n_(len(s))
0068     {
0069     }
0070 
0071     BOOST_URL_DECL
0072     system::result<value_type>
0073     parse(
0074         char const*& it,
0075         char const* end) const noexcept;
0076 };
0077 
0078 } // grammar
0079 } // urls
0080 } // boost
0081 
0082 #endif