100.00% Lines (12/12)
100.00% Functions (2/2)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) | 2 | // Copyright (c) 2021 Vinnie Falco (vinnie.falco@gmail.com) | |||||
| 3 | // | 3 | // | |||||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 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) | 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 6 | // | 6 | // | |||||
| 7 | // Official repository: https://github.com/cppalliance/http | 7 | // Official repository: https://github.com/cppalliance/http | |||||
| 8 | // | 8 | // | |||||
| 9 | 9 | |||||||
| 10 | #ifndef BOOST_HTTP_RFC_QUOTED_TOKEN_VIEW_HPP | 10 | #ifndef BOOST_HTTP_RFC_QUOTED_TOKEN_VIEW_HPP | |||||
| 11 | #define BOOST_HTTP_RFC_QUOTED_TOKEN_VIEW_HPP | 11 | #define BOOST_HTTP_RFC_QUOTED_TOKEN_VIEW_HPP | |||||
| 12 | 12 | |||||||
| 13 | #include <boost/http/detail/config.hpp> | 13 | #include <boost/http/detail/config.hpp> | |||||
| 14 | #include <boost/url/grammar/string_view_base.hpp> | 14 | #include <boost/url/grammar/string_view_base.hpp> | |||||
| 15 | #include <boost/core/detail/string_view.hpp> | 15 | #include <boost/core/detail/string_view.hpp> | |||||
| 16 | 16 | |||||||
| 17 | namespace boost { | 17 | namespace boost { | |||||
| 18 | namespace http { | 18 | namespace http { | |||||
| 19 | 19 | |||||||
| 20 | namespace implementation_defined { | 20 | namespace implementation_defined { | |||||
| 21 | struct quoted_token_rule_t; | 21 | struct quoted_token_rule_t; | |||||
| 22 | } // implementation_defined | 22 | } // implementation_defined | |||||
| 23 | 23 | |||||||
| 24 | /** A view into a quoted string token, which may | 24 | /** A view into a quoted string token, which may | |||||
| 25 | contain escape sequences. | 25 | contain escape sequences. | |||||
| 26 | 26 | |||||||
| 27 | @see | 27 | @see | |||||
| 28 | @ref quoted_token_view. | 28 | @ref quoted_token_view. | |||||
| 29 | */ | 29 | */ | |||||
| 30 | class quoted_token_view final | 30 | class quoted_token_view final | |||||
| 31 | : public grammar::string_view_base | 31 | : public grammar::string_view_base | |||||
| 32 | { | 32 | { | |||||
| 33 | std::size_t n_ = 0; | 33 | std::size_t n_ = 0; | |||||
| 34 | 34 | |||||||
| 35 | friend struct implementation_defined::quoted_token_rule_t; | 35 | friend struct implementation_defined::quoted_token_rule_t; | |||||
| 36 | 36 | |||||||
| 37 | // unquoted | 37 | // unquoted | |||||
| 38 | explicit | 38 | explicit | |||||
| HITCBC | 39 | 15 | quoted_token_view( | 39 | 15 | quoted_token_view( | ||
| 40 | core::string_view s) noexcept | 40 | core::string_view s) noexcept | |||||
| HITCBC | 41 | 15 | : string_view_base(s) | 41 | 15 | : string_view_base(s) | ||
| HITCBC | 42 | 15 | , n_(s.size()) | 42 | 15 | , n_(s.size()) | ||
| 43 | { | 43 | { | |||||
| HITCBC | 44 | 15 | } | 44 | 15 | } | ||
| 45 | 45 | |||||||
| 46 | // maybe quoted | 46 | // maybe quoted | |||||
| HITCBC | 47 | 6 | quoted_token_view( | 47 | 6 | quoted_token_view( | ||
| 48 | core::string_view s, | 48 | core::string_view s, | |||||
| 49 | std::size_t n) noexcept | 49 | std::size_t n) noexcept | |||||
| HITCBC | 50 | 6 | : string_view_base(s) | 50 | 6 | : string_view_base(s) | ||
| HITCBC | 51 | 6 | , n_(n) | 51 | 6 | , n_(n) | ||
| 52 | { | 52 | { | |||||
| HITCBC | 53 | 6 | BOOST_ASSERT(s.size() >= 2); | 53 | 6 | BOOST_ASSERT(s.size() >= 2); | ||
| HITCBC | 54 | 6 | BOOST_ASSERT(s.front() == '\"'); | 54 | 6 | BOOST_ASSERT(s.front() == '\"'); | ||
| HITCBC | 55 | 6 | BOOST_ASSERT(s.back() == '\"'); | 55 | 6 | BOOST_ASSERT(s.back() == '\"'); | ||
| HITCBC | 56 | 6 | BOOST_ASSERT(n_ <= s_.size() - 2); | 56 | 6 | BOOST_ASSERT(n_ <= s_.size() - 2); | ||
| HITCBC | 57 | 6 | } | 57 | 6 | } | ||
| 58 | 58 | |||||||
| 59 | public: | 59 | public: | |||||
| 60 | quoted_token_view() = default; | 60 | quoted_token_view() = default; | |||||
| 61 | 61 | |||||||
| 62 | quoted_token_view( | 62 | quoted_token_view( | |||||
| 63 | quoted_token_view const&) noexcept = default; | 63 | quoted_token_view const&) noexcept = default; | |||||
| 64 | 64 | |||||||
| 65 | quoted_token_view& operator=( | 65 | quoted_token_view& operator=( | |||||
| 66 | quoted_token_view const&) noexcept = default; | 66 | quoted_token_view const&) noexcept = default; | |||||
| 67 | 67 | |||||||
| 68 | /** Return true if the token contains escape | 68 | /** Return true if the token contains escape | |||||
| 69 | sequences. | 69 | sequences. | |||||
| 70 | 70 | |||||||
| 71 | @par Complexity | 71 | @par Complexity | |||||
| 72 | Constant. | 72 | Constant. | |||||
| 73 | 73 | |||||||
| 74 | @Return true if the token contains | 74 | @Return true if the token contains | |||||
| 75 | escape sequences. | 75 | escape sequences. | |||||
| 76 | */ | 76 | */ | |||||
| 77 | bool | 77 | bool | |||||
| 78 | has_escapes() const noexcept | 78 | has_escapes() const noexcept | |||||
| 79 | { | 79 | { | |||||
| 80 | return n_ != s_.size(); | 80 | return n_ != s_.size(); | |||||
| 81 | } | 81 | } | |||||
| 82 | 82 | |||||||
| 83 | /** Return the size of the unescaped content. | 83 | /** Return the size of the unescaped content. | |||||
| 84 | 84 | |||||||
| 85 | @par Complexity | 85 | @par Complexity | |||||
| 86 | Constant. | 86 | Constant. | |||||
| 87 | 87 | |||||||
| 88 | @return Size of the unescaped string content. | 88 | @return Size of the unescaped string content. | |||||
| 89 | */ | 89 | */ | |||||
| 90 | std::size_t | 90 | std::size_t | |||||
| 91 | unescaped_size() const noexcept | 91 | unescaped_size() const noexcept | |||||
| 92 | { | 92 | { | |||||
| 93 | return n_; | 93 | return n_; | |||||
| 94 | } | 94 | } | |||||
| 95 | }; | 95 | }; | |||||
| 96 | 96 | |||||||
| 97 | } // http | 97 | } // http | |||||
| 98 | } // boost | 98 | } // boost | |||||
| 99 | 99 | |||||||
| 100 | #endif | 100 | #endif | |||||