GCC Code Coverage Report


Directory: libs/url/
File: boost/url/detail/url_impl.hpp
Date: 2024-03-13 19:32:03
Exec Total Coverage
Lines: 18 18 100.0%
Functions: 6 6 100.0%
Branches: 12 20 60.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2022 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/boostorg/url
8 //
9
10 #ifndef BOOST_URL_DETAIL_URL_IMPL_HPP
11 #define BOOST_URL_DETAIL_URL_IMPL_HPP
12
13 #include <boost/url/host_type.hpp>
14 #include <boost/url/pct_string_view.hpp>
15 #include <boost/url/scheme.hpp>
16 #include <boost/core/detail/string_view.hpp>
17 #include <boost/url/detail/parts_base.hpp>
18 #include <boost/assert.hpp>
19 #include <cstdint>
20
21 namespace boost {
22 namespace urls {
23
24 class url_view;
25 class authority_view;
26
27 namespace detail {
28
29 constexpr char const* const empty_c_str_ = "";
30
31 // This is the private 'guts' of a
32 // url_view, exposed so different parts
33 // of the implementation can work on it.
34 struct BOOST_URL_DECL url_impl : parts_base
35 {
36 static
37 constexpr
38 std::size_t const zero_ = 0;
39
40 // never nullptr
41 char const* cs_ = empty_c_str_;
42
43 std::size_t offset_[id_end + 1] = {};
44 std::size_t decoded_[id_end] = {};
45 std::size_t nseg_ = 0;
46 std::size_t nparam_ = 0;
47 unsigned char ip_addr_[16] = {};
48 // VFALCO don't we need a bool?
49 std::uint16_t port_number_ = 0;
50 host_type host_type_ =
51 urls::host_type::none;
52 scheme scheme_ =
53 urls::scheme::none;
54
55 from from_ = from::string;
56
57 16729 url_impl(
58 from b) noexcept
59 16729 : from_(b)
60 {
61 16729 }
62
63 // in url_view.ipp
64 url_view construct() const noexcept;
65
66 // in authority_view.ipp
67 authority_view
68 construct_authority() const noexcept;
69
70 std::size_t len(int, int) const noexcept;
71 std::size_t len(int) const noexcept;
72 std::size_t offset(int) const noexcept;
73 core::string_view get(int) const noexcept;
74 core::string_view get(int, int) const noexcept;
75 pct_string_view pct_get(int) const noexcept;
76 pct_string_view pct_get(int, int) const noexcept;
77 void set_size(int, std::size_t) noexcept;
78 void split(int, std::size_t) noexcept;
79 void adjust_right(int first, int last, std::size_t n) noexcept;
80 void adjust_left(int first, int last, std::size_t n) noexcept;
81 void collapse(int, int, std::size_t) noexcept;
82
83 void apply_scheme(core::string_view) noexcept;
84 void apply_userinfo(pct_string_view const&,
85 pct_string_view const*) noexcept;
86 void apply_host(host_type, pct_string_view,
87 unsigned char const*) noexcept;
88 void apply_port(core::string_view, unsigned short) noexcept;
89 void apply_authority(authority_view const&) noexcept;
90 void apply_path(pct_string_view, std::size_t) noexcept;
91 void apply_query(pct_string_view, std::size_t) noexcept;
92 void apply_frag(pct_string_view) noexcept;
93 };
94
95 //------------------------------------------------
96
97 // this allows a path to come from a
98 // url_impl or a separate core::string_view
99 class path_ref
100 : private parts_base
101 {
102 url_impl const* impl_ = nullptr;
103 char const* data_ = nullptr;
104 std::size_t size_ = 0;
105 std::size_t nseg_ = 0;
106 std::size_t dn_ = 0;
107
108 public:
109 path_ref() = default;
110 path_ref(url_impl const& impl) noexcept;
111 path_ref(core::string_view,
112 std::size_t, std::size_t) noexcept;
113 pct_string_view buffer() const noexcept;
114 std::size_t size() const noexcept;
115 char const* data() const noexcept;
116 char const* end() const noexcept;
117 std::size_t nseg() const noexcept;
118
119 bool
120 1194 alias_of(
121 url_impl const& impl) const noexcept
122 {
123 1194 return impl_ == &impl;
124 }
125
126 bool
127 5082 alias_of(
128 path_ref const& ref) const noexcept
129 {
130
2/2
✓ Branch 0 taken 2463 times.
✓ Branch 1 taken 2619 times.
5082 if(impl_)
131 2463 return impl_ == ref.impl_;
132
4/8
✓ Branch 0 taken 2619 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2619 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2619 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2619 times.
✗ Branch 7 not taken.
2619 BOOST_ASSERT(data_ != ref.data_ || (
133 size_ == ref.size_ &&
134 nseg_ == ref.nseg_ &&
135 dn_ == ref.dn_));
136 2619 return data_ == ref.data_;
137 }
138 };
139
140 //------------------------------------------------
141
142 // this allows a params to come from a
143 // url_impl or a separate core::string_view
144 class BOOST_URL_DECL query_ref
145 : private parts_base
146 {
147 url_impl const* impl_ = nullptr;
148 char const* data_ = nullptr;
149 std::size_t size_ = 0;
150 std::size_t nparam_ = 0;
151 std::size_t dn_ = 0;
152 bool question_mark_ = false;
153
154 public:
155 query_ref(
156 core::string_view s, // buffer, no '?'
157 std::size_t dn, // decoded size
158 std::size_t nparam
159 ) noexcept;
160 9 query_ref() = default;
161 query_ref(url_impl const& impl) noexcept;
162 pct_string_view buffer() const noexcept;
163 std::size_t size() const noexcept; // with '?'
164 char const* begin() const noexcept; // no '?'
165 char const* end() const noexcept;
166 std::size_t nparam() const noexcept;
167
168 bool
169 276 alias_of(
170 url_impl const& impl) const noexcept
171 {
172 276 return impl_ == &impl;
173 }
174
175 bool
176 2449 alias_of(
177 query_ref const& ref) const noexcept
178 {
179
2/2
✓ Branch 0 taken 718 times.
✓ Branch 1 taken 1731 times.
2449 if(impl_)
180 718 return impl_ == ref.impl_;
181
4/8
✓ Branch 0 taken 1731 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1731 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1731 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1731 times.
✗ Branch 7 not taken.
1731 BOOST_ASSERT(data_ != ref.data_ || (
182 size_ == ref.size_ &&
183 nparam_ == ref.nparam_ &&
184 dn_ == ref.dn_));
185 1731 return data_ == ref.data_;
186 }
187 };
188
189 } // detail
190
191 } // urls
192 } // boost
193
194 #endif
195