Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:53:57

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_PARSE_HPP
0011 #define BOOST_URL_GRAMMAR_PARSE_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 <boost/url/grammar/type_traits.hpp>
0017 
0018 namespace boost {
0019 namespace urls {
0020 namespace grammar {
0021 
0022 //------------------------------------------------
0023 
0024 /** Parse a character buffer using a rule
0025 
0026     @param it A pointer to the start. The
0027     caller's variable is changed to
0028     reflect the amount of input consumed.
0029 
0030     @param end A pointer to the end.
0031 
0032     @param r The rule to use
0033 
0034     @return The parsed value upon success,
0035     otherwise an error.
0036 */
0037 template<BOOST_URL_CONSTRAINT(Rule) R>
0038 system::result<typename R::value_type>
0039 parse(
0040     char const*& it,
0041     char const* end,
0042     R const& r);
0043 
0044 /** Parse a character buffer using a rule
0045 
0046     This function parses a complete string into
0047     the specified sequence of rules. If the
0048     string is not completely consumed, an
0049     error is returned instead.
0050 
0051     @param s The input string
0052 
0053     @param r The rule to use
0054 
0055     @return The parsed value upon success,
0056     otherwise an error.
0057 */
0058 template<BOOST_URL_CONSTRAINT(Rule) R>
0059 system::result<typename R::value_type>
0060 parse(
0061     core::string_view s,
0062     R const& r);
0063 
0064 //------------------------------------------------
0065 
0066 namespace implementation_defined {
0067 template<class Rule>
0068 struct rule_ref
0069 {
0070     Rule const& r_;
0071 
0072     using value_type =
0073         typename Rule::value_type;
0074 
0075     system::result<value_type>
0076     parse(
0077         char const*& it,
0078         char const* end) const
0079     {
0080         return r_.parse(it, end);
0081     }
0082 };
0083 } // implementation_defined
0084 
0085 /** Return a reference to a rule
0086 
0087     This function returns a rule which
0088     references the specified object. This is
0089     used to reduce the number of bytes of
0090     storage (`sizeof`) required by a combinator
0091     when it stores a copy of the object.
0092     <br>
0093     Ownership of the object is not transferred;
0094     the caller is responsible for ensuring the
0095     lifetime of the object is extended until it
0096     is no longer referenced. For best results,
0097     `ref` should only be used with compile-time
0098     constants.
0099 
0100     @param r The rule to use
0101     @return The rule as a reference type
0102 */
0103 template<BOOST_URL_CONSTRAINT(Rule) R>
0104 constexpr
0105 typename std::enable_if<
0106     is_rule<R>::value &&
0107     ! std::is_same<R,
0108         implementation_defined::rule_ref<R> >::value,
0109     implementation_defined::rule_ref<R> >::type
0110 ref(R const& r) noexcept
0111 {
0112     return implementation_defined::rule_ref<R>{r};
0113 }
0114 
0115 #ifndef BOOST_URL_DOCS
0116 #ifndef BOOST_URL_MRDOCS
0117 // If you get a compile error here it
0118 // means you called ref with something
0119 // that is not a CharSet or Rule!
0120 constexpr
0121 void
0122 ref(...) = delete;
0123 #endif
0124 #endif
0125 
0126 } // grammar
0127 } // urls
0128 } // boost
0129 
0130 #include <boost/url/grammar/impl/parse.hpp>
0131 
0132 #endif