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