include/boost/url/impl/static_url.hpp

100.0% Lines (22/24) 100.0% List of functions (4/5)
static_url.hpp
f(x) Functions (5)
Line TLA Hits Source Code
1 //
2 // Copyright (c) 2019 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_IMPL_STATIC_URL_HPP
11 #define BOOST_URL_IMPL_STATIC_URL_HPP
12
13 #include <boost/url/detail/except.hpp>
14 #include <boost/assert.hpp>
15
16 namespace boost {
17 namespace urls {
18
19 inline
20 39x static_url_base::
21 static_url_base(
22 char* buf,
23 39x std::size_t cap) noexcept
24 {
25 39x s_ = buf;
26 39x cap_ = cap;
27 39x s_[0] = '\0';
28 39x impl_.cs_ = s_;
29 39x }
30
31 inline
32 18x static_url_base::
33 static_url_base(
34 char* buf,
35 std::size_t cap,
36 18x core::string_view s)
37 18x : static_url_base(buf, cap)
38 {
39 37x copy(parse_uri_reference(s
40 21x ).value(BOOST_URL_POS));
41 18x }
42
43 inline
44 void
45 1x static_url_base::
46 clear_impl() noexcept
47 {
48 1x impl_ = {from::url};
49 1x s_[0] = '\0';
50 1x impl_.cs_ = s_;
51 1x }
52
53 inline
54 void
55 55x static_url_base::
56 reserve_impl(
57 std::size_t n,
58 op_t&)
59 {
60 55x if(n <= cap_)
61 51x return;
62 4x detail::throw_length_error();
63 }
64
65 //----------------------------------------------------------
66
67 // LCOV_EXCL_START
68 inline
69 void
70 static_url_base::
71 cleanup(op_t&)
72 {
73 /*
74 * The cleanup function is a blank
75 * override as it's unreachable
76 * for static_url_base.
77 *
78 * `u.cleanup()` is called by `op_t` when
79 * the `op_t::old` string is being replaced.
80 * This never happens for `static_url_base`
81 * because it always uses the same buffer.
82 *
83 * `url::reserve_impl` is the only function
84 * that sets the `op_t::old` string but
85 * `static_url_base::reserve_impl` does
86 * not touch `op_t::old`.
87 */
88 }
89 // LCOV_EXCL_STOP
90
91 } // urls
92 } // boost
93
94 #endif
95