libs/url/include/boost/url/grammar/parse.hpp
100.0% Lines (4/4)
100.0% Functions (2/2)
-% Branches (0/0)
libs/url/include/boost/url/grammar/parse.hpp
| Line | Hits | Source Code |
|---|---|---|
| 1 | // | |
| 2 | // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) | |
| 3 | // | |
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
| 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
| 6 | // | |
| 7 | // Official repository: https://github.com/boostorg/url | |
| 8 | // | |
| 9 | ||
| 10 | #ifndef BOOST_URL_GRAMMAR_PARSE_HPP | |
| 11 | #define BOOST_URL_GRAMMAR_PARSE_HPP | |
| 12 | ||
| 13 | #include <boost/url/detail/config.hpp> | |
| 14 | #include <boost/url/error_types.hpp> | |
| 15 | #include <boost/core/detail/string_view.hpp> | |
| 16 | #include <boost/url/grammar/type_traits.hpp> | |
| 17 | ||
| 18 | namespace boost { | |
| 19 | namespace urls { | |
| 20 | namespace grammar { | |
| 21 | ||
| 22 | //------------------------------------------------ | |
| 23 | ||
| 24 | /** Parse a character buffer using a rule | |
| 25 | ||
| 26 | @param it A pointer to the start. The | |
| 27 | caller's variable is changed to | |
| 28 | reflect the amount of input consumed. | |
| 29 | ||
| 30 | @param end A pointer to the end. | |
| 31 | ||
| 32 | @param r The rule to use | |
| 33 | ||
| 34 | @return The parsed value upon success, | |
| 35 | otherwise an error. | |
| 36 | */ | |
| 37 | template<BOOST_URL_CONSTRAINT(Rule) R> | |
| 38 | system::result<typename R::value_type> | |
| 39 | parse( | |
| 40 | char const*& it, | |
| 41 | char const* end, | |
| 42 | R const& r); | |
| 43 | ||
| 44 | /** Parse a character buffer using a rule | |
| 45 | ||
| 46 | This function parses a complete string into | |
| 47 | the specified sequence of rules. If the | |
| 48 | string is not completely consumed, an | |
| 49 | error is returned instead. | |
| 50 | ||
| 51 | @param s The input string | |
| 52 | ||
| 53 | @param r The rule to use | |
| 54 | ||
| 55 | @return The parsed value upon success, | |
| 56 | otherwise an error. | |
| 57 | */ | |
| 58 | template<BOOST_URL_CONSTRAINT(Rule) R> | |
| 59 | system::result<typename R::value_type> | |
| 60 | parse( | |
| 61 | core::string_view s, | |
| 62 | R const& r); | |
| 63 | ||
| 64 | //------------------------------------------------ | |
| 65 | ||
| 66 | namespace implementation_defined { | |
| 67 | template<class Rule> | |
| 68 | struct rule_ref | |
| 69 | { | |
| 70 | Rule const& r_; | |
| 71 | ||
| 72 | using value_type = | |
| 73 | typename Rule::value_type; | |
| 74 | ||
| 75 | system::result<value_type> | |
| 76 | 1 | parse( |
| 77 | char const*& it, | |
| 78 | char const* end) const | |
| 79 | { | |
| 80 | 1 | return r_.parse(it, end); |
| 81 | } | |
| 82 | }; | |
| 83 | } // implementation_defined | |
| 84 | ||
| 85 | /** Return a reference to a rule | |
| 86 | ||
| 87 | This function returns a rule which | |
| 88 | references the specified object. This is | |
| 89 | used to reduce the number of bytes of | |
| 90 | storage (`sizeof`) required by a combinator | |
| 91 | when it stores a copy of the object. | |
| 92 | <br> | |
| 93 | Ownership of the object is not transferred; | |
| 94 | the caller is responsible for ensuring the | |
| 95 | lifetime of the object is extended until it | |
| 96 | is no longer referenced. For best results, | |
| 97 | `ref` should only be used with compile-time | |
| 98 | constants. | |
| 99 | ||
| 100 | @param r The rule to use | |
| 101 | @return The rule as a reference type | |
| 102 | */ | |
| 103 | template<BOOST_URL_CONSTRAINT(Rule) R> | |
| 104 | constexpr | |
| 105 | typename std::enable_if< | |
| 106 | is_rule<R>::value && | |
| 107 | ! std::is_same<R, | |
| 108 | implementation_defined::rule_ref<R> >::value, | |
| 109 | implementation_defined::rule_ref<R> >::type | |
| 110 | 1 | ref(R const& r) noexcept |
| 111 | { | |
| 112 | 1 | return implementation_defined::rule_ref<R>{r}; |
| 113 | } | |
| 114 | ||
| 115 | #ifndef BOOST_URL_DOCS | |
| 116 | #ifndef BOOST_URL_MRDOCS | |
| 117 | // If you get a compile error here it | |
| 118 | // means you called ref with something | |
| 119 | // that is not a CharSet or Rule! | |
| 120 | constexpr | |
| 121 | void | |
| 122 | ref(...) = delete; | |
| 123 | #endif | |
| 124 | #endif | |
| 125 | ||
| 126 | } // grammar | |
| 127 | } // urls | |
| 128 | } // boost | |
| 129 | ||
| 130 | #include <boost/url/grammar/impl/parse.hpp> | |
| 131 | ||
| 132 | #endif | |
| 133 |