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