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