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