Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:27

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 #ifdef BOOST_URL_DOCS
0045 constexpr
0046 __implementation_defined__
0047 literal_rule( char const* s );
0048 #else
0049 class literal_rule
0050 {
0051     char const* s_ = nullptr;
0052     std::size_t n_ = 0;
0053 
0054     constexpr
0055     static
0056     std::size_t
0057     len(char const* s) noexcept
0058     {
0059         return *s
0060             ? 1 + len(s + 1)
0061             : 0;
0062     }
0063 
0064 public:
0065     using value_type = core::string_view;
0066 
0067     constexpr
0068     explicit
0069     literal_rule(
0070         char const* s) noexcept
0071         : s_(s)
0072         , n_(len(s))
0073     {
0074     }
0075 
0076     BOOST_URL_DECL
0077     system::result<value_type>
0078     parse(
0079         char const*& it,
0080         char const* end) const noexcept;
0081 };
0082 #endif
0083 
0084 } // grammar
0085 } // urls
0086 } // boost
0087 
0088 #endif