TLA Line data Source code
1 : //
2 : // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3 : // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
4 : //
5 : // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 : // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 : //
8 : // Official repository: https://github.com/boostorg/url
9 : //
10 :
11 : #ifndef BOOST_URL_IMPL_URL_VIEW_HPP
12 : #define BOOST_URL_IMPL_URL_VIEW_HPP
13 :
14 : #include <boost/url/parse.hpp>
15 : #include <boost/url/detail/over_allocator.hpp>
16 : #include <cstring>
17 : #include <memory>
18 :
19 : namespace boost {
20 : namespace urls {
21 :
22 : //------------------------------------------------
23 : //
24 : // url_view
25 : //
26 : //------------------------------------------------
27 :
28 : inline
29 HIT 388 : url_view::
30 388 : url_view(core::string_view s)
31 388 : : url_view(parse_uri_reference(s
32 388 : ).value(BOOST_URL_POS))
33 : {
34 387 : }
35 :
36 : //------------------------------------------------
37 : //
38 : // url_view_base::persist
39 : //
40 : //------------------------------------------------
41 :
42 : struct url_view_base::shared_impl
43 : : url_view
44 : {
45 : virtual
46 4 : ~shared_impl()
47 4 : {
48 4 : }
49 :
50 4 : shared_impl(
51 : url_view const& u) noexcept
52 4 : : url_view(u)
53 : {
54 4 : impl_.cs_ = reinterpret_cast<
55 : char const*>(this + 1);
56 4 : }
57 : };
58 :
59 : inline
60 : std::shared_ptr<url_view const>
61 4 : url_view_base::
62 : persist() const
63 : {
64 : using T = shared_impl;
65 : using Alloc = std::allocator<char>;
66 : Alloc a;
67 : auto p = std::allocate_shared<T>(
68 8 : detail::over_allocator<T, Alloc>(
69 8 : size(), a), url_view(impl()));
70 4 : if(size())
71 3 : std::memcpy(
72 : reinterpret_cast<char*>(
73 3 : p.get() + 1), data(), size());
74 8 : return p;
75 4 : }
76 :
77 : } // urls
78 : } // boost
79 :
80 : #endif
|