| Line | Branch | Exec | Source |
|---|---|---|---|
| 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_LITERAL_RULE_HPP | ||
| 11 | #define BOOST_URL_GRAMMAR_LITERAL_RULE_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 <cstdlib> | ||
| 17 | |||
| 18 | namespace boost { | ||
| 19 | namespace urls { | ||
| 20 | namespace grammar { | ||
| 21 | |||
| 22 | /** Match a string literal exactly | ||
| 23 | |||
| 24 | If there is no more input, or if the | ||
| 25 | end of the input is reached, and a prefix | ||
| 26 | of the literal matches exactly, the error | ||
| 27 | returned is @ref error::need_more. | ||
| 28 | |||
| 29 | @par Value Type | ||
| 30 | @code | ||
| 31 | using value_type = core::string_view; | ||
| 32 | @endcode | ||
| 33 | |||
| 34 | @par Example | ||
| 35 | Rules are used with the function @ref parse. | ||
| 36 | @code | ||
| 37 | system::result< core::string_view > rv = parse( "HTTP", literal_rule( "HTTP" ) ); | ||
| 38 | @endcode | ||
| 39 | |||
| 40 | @see | ||
| 41 | @ref delim_rule, | ||
| 42 | @ref parse. | ||
| 43 | */ | ||
| 44 | class literal_rule | ||
| 45 | { | ||
| 46 | char const* s_ = nullptr; | ||
| 47 | std::size_t n_ = 0; | ||
| 48 | |||
| 49 | constexpr | ||
| 50 | static | ||
| 51 | std::size_t | ||
| 52 | 48 | len(char const* s) noexcept | |
| 53 | { | ||
| 54 | 48 | return *s | |
| 55 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 10 times.
|
48 | ? 1 + len(s + 1) |
| 56 | 48 | : 0; | |
| 57 | } | ||
| 58 | |||
| 59 | public: | ||
| 60 | using value_type = core::string_view; | ||
| 61 | |||
| 62 | constexpr | ||
| 63 | explicit | ||
| 64 | 10 | literal_rule( | |
| 65 | char const* s) noexcept | ||
| 66 | 10 | : s_(s) | |
| 67 | 10 | , n_(len(s)) | |
| 68 | { | ||
| 69 | 10 | } | |
| 70 | |||
| 71 | BOOST_URL_DECL | ||
| 72 | system::result<value_type> | ||
| 73 | parse( | ||
| 74 | char const*& it, | ||
| 75 | char const* end) const noexcept; | ||
| 76 | }; | ||
| 77 | |||
| 78 | } // grammar | ||
| 79 | } // urls | ||
| 80 | } // boost | ||
| 81 | |||
| 82 | #endif | ||
| 83 |