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 375 : url_view::
30 375 : url_view(core::string_view s)
31 375 : : url_view(parse_uri_reference(s
32 375 : ).value(BOOST_URL_POS))
33 : {
34 374 : }
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 3 : ~shared_impl()
47 3 : {
48 3 : }
49 :
50 3 : shared_impl(
51 : url_view const& u) noexcept
52 3 : : url_view(u)
53 : {
54 3 : impl_.cs_ = reinterpret_cast<
55 : char const*>(this + 1);
56 3 : }
57 : };
58 :
59 : inline
60 : std::shared_ptr<url_view const>
61 3 : 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 6 : detail::over_allocator<T, Alloc>(
69 6 : size(), a), url_view(impl()));
70 3 : std::memcpy(
71 : reinterpret_cast<char*>(
72 3 : p.get() + 1), data(), size());
73 6 : return p;
74 3 : }
75 :
76 : } // urls
77 : } // boost
78 :
79 : #endif
|