1  
//
1  
//
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3  
// Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
3  
// Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
4  
//
4  
//
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
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)
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  
//
7  
//
8  
// Official repository: https://github.com/boostorg/url
8  
// Official repository: https://github.com/boostorg/url
9  
//
9  
//
10  

10  

11  
#ifndef BOOST_URL_IMPL_URL_VIEW_HPP
11  
#ifndef BOOST_URL_IMPL_URL_VIEW_HPP
12  
#define BOOST_URL_IMPL_URL_VIEW_HPP
12  
#define BOOST_URL_IMPL_URL_VIEW_HPP
13  

13  

14  
#include <boost/url/parse.hpp>
14  
#include <boost/url/parse.hpp>
15  
#include <boost/url/detail/over_allocator.hpp>
15  
#include <boost/url/detail/over_allocator.hpp>
16  
#include <cstring>
16  
#include <cstring>
17  
#include <memory>
17  
#include <memory>
18  

18  

19  
namespace boost {
19  
namespace boost {
20  
namespace urls {
20  
namespace urls {
21  

21  

22  
//------------------------------------------------
22  
//------------------------------------------------
23  
//
23  
//
24  
// url_view
24  
// url_view
25  
//
25  
//
26  
//------------------------------------------------
26  
//------------------------------------------------
27  

27  

28  
inline
28  
inline
29  
url_view::
29  
url_view::
30  
url_view(core::string_view s)
30  
url_view(core::string_view s)
31  
    : url_view(parse_uri_reference(s
31  
    : url_view(parse_uri_reference(s
32  
        ).value(BOOST_URL_POS))
32  
        ).value(BOOST_URL_POS))
33  
{
33  
{
34  
}
34  
}
35  

35  

36  
//------------------------------------------------
36  
//------------------------------------------------
37  
//
37  
//
38  
// url_view_base::persist
38  
// url_view_base::persist
39  
//
39  
//
40  
//------------------------------------------------
40  
//------------------------------------------------
41  

41  

42  
struct url_view_base::shared_impl
42  
struct url_view_base::shared_impl
43  
    : url_view
43  
    : url_view
44  
{
44  
{
45  
    virtual
45  
    virtual
46  
    ~shared_impl()
46  
    ~shared_impl()
47  
    {
47  
    {
48  
    }
48  
    }
49  

49  

50  
    shared_impl(
50  
    shared_impl(
51  
        url_view const& u) noexcept
51  
        url_view const& u) noexcept
52  
        : url_view(u)
52  
        : url_view(u)
53  
    {
53  
    {
54  
        impl_.cs_ = reinterpret_cast<
54  
        impl_.cs_ = reinterpret_cast<
55  
            char const*>(this + 1);
55  
            char const*>(this + 1);
56  
    }
56  
    }
57  
};
57  
};
58  

58  

59  
inline
59  
inline
60  
std::shared_ptr<url_view const>
60  
std::shared_ptr<url_view const>
61  
url_view_base::
61  
url_view_base::
62  
persist() const
62  
persist() const
63  
{
63  
{
64  
    using T = shared_impl;
64  
    using T = shared_impl;
65  
    using Alloc = std::allocator<char>;
65  
    using Alloc = std::allocator<char>;
66  
    Alloc a;
66  
    Alloc a;
67  
    auto p = std::allocate_shared<T>(
67  
    auto p = std::allocate_shared<T>(
68  
        detail::over_allocator<T, Alloc>(
68  
        detail::over_allocator<T, Alloc>(
69  
            size(), a), url_view(impl()));
69  
            size(), a), url_view(impl()));
70  
    std::memcpy(
70  
    std::memcpy(
71  
        reinterpret_cast<char*>(
71  
        reinterpret_cast<char*>(
72  
            p.get() + 1), data(), size());
72  
            p.get() + 1), data(), size());
73  
    return p;
73  
    return p;
74  
}
74  
}
75  

75  

76  
} // urls
76  
} // urls
77  
} // boost
77  
} // boost
78  

78  

79  
#endif
79  
#endif