| 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 | #ifdef BOOST_URL_DOCS | ||
| 45 | constexpr | ||
| 46 | __implementation_defined__ | ||
| 47 | literal_rule( char const* s ); | ||
| 48 | #else | ||
| 49 | class literal_rule | ||
| 50 | { | ||
| 51 | char const* s_ = nullptr; | ||
| 52 | std::size_t n_ = 0; | ||
| 53 | |||
| 54 | constexpr | ||
| 55 | static | ||
| 56 | std::size_t | ||
| 57 | 48 | len(char const* s) noexcept | |
| 58 | { | ||
| 59 | 48 | return *s | |
| 60 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 10 times.
|
48 | ? 1 + len(s + 1) |
| 61 | 48 | : 0; | |
| 62 | } | ||
| 63 | |||
| 64 | public: | ||
| 65 | using value_type = core::string_view; | ||
| 66 | |||
| 67 | constexpr | ||
| 68 | explicit | ||
| 69 | 10 | literal_rule( | |
| 70 | char const* s) noexcept | ||
| 71 | 10 | : s_(s) | |
| 72 | 10 | , n_(len(s)) | |
| 73 | { | ||
| 74 | 10 | } | |
| 75 | |||
| 76 | BOOST_URL_DECL | ||
| 77 | system::result<value_type> | ||
| 78 | parse( | ||
| 79 | char const*& it, | ||
| 80 | char const* end) const noexcept; | ||
| 81 | }; | ||
| 82 | #endif | ||
| 83 | |||
| 84 | } // grammar | ||
| 85 | } // urls | ||
| 86 | } // boost | ||
| 87 | |||
| 88 | #endif | ||
| 89 |