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

9  

10  

10  

11  
#include <boost/url/detail/config.hpp>
11  
#include <boost/url/detail/config.hpp>
12  
#include <boost/url/parse.hpp>
12  
#include <boost/url/parse.hpp>
13  
#include <boost/url/static_url.hpp>
13  
#include <boost/url/static_url.hpp>
14  
#include <boost/url/url_view.hpp>
14  
#include <boost/url/url_view.hpp>
15  
#include <boost/url/detail/except.hpp>
15  
#include <boost/url/detail/except.hpp>
16  
#include <boost/assert.hpp>
16  
#include <boost/assert.hpp>
17  

17  

18  
namespace boost {
18  
namespace boost {
19  
namespace urls {
19  
namespace urls {
20  

20  

21  
static_url_base::
21  
static_url_base::
22  
static_url_base(
22  
static_url_base(
23  
    char* buf,
23  
    char* buf,
24  
    std::size_t cap) noexcept
24  
    std::size_t cap) noexcept
25  
{
25  
{
26  
    s_ = buf;
26  
    s_ = buf;
27  
    cap_ = cap;
27  
    cap_ = cap;
28  
    s_[0] = '\0';
28  
    s_[0] = '\0';
29  
    impl_.cs_ = s_;
29  
    impl_.cs_ = s_;
30  
}
30  
}
31  

31  

32  
static_url_base::
32  
static_url_base::
33  
static_url_base(
33  
static_url_base(
34  
    char* buf,
34  
    char* buf,
35  
    std::size_t cap,
35  
    std::size_t cap,
36  
    core::string_view s)
36  
    core::string_view s)
37  
    : static_url_base(buf, cap)
37  
    : static_url_base(buf, cap)
38  
{
38  
{
39  
    copy(parse_uri_reference(s
39  
    copy(parse_uri_reference(s
40  
        ).value(BOOST_URL_POS));
40  
        ).value(BOOST_URL_POS));
41  
}
41  
}
42  

42  

43  
void
43  
void
44  
static_url_base::
44  
static_url_base::
45  
clear_impl() noexcept
45  
clear_impl() noexcept
46  
{
46  
{
47  
    impl_ = {from::url};
47  
    impl_ = {from::url};
48  
    s_[0] = '\0';
48  
    s_[0] = '\0';
49  
    impl_.cs_ = s_;
49  
    impl_.cs_ = s_;
50  
}
50  
}
51  

51  

52  
void
52  
void
53  
static_url_base::
53  
static_url_base::
54  
reserve_impl(
54  
reserve_impl(
55  
    std::size_t n,
55  
    std::size_t n,
56  
    op_t&)
56  
    op_t&)
57  
{
57  
{
58  
    if(n <= cap_)
58  
    if(n <= cap_)
59  
        return;
59  
        return;
60  
    detail::throw_length_error();
60  
    detail::throw_length_error();
61  
}
61  
}
62  

62  

63  
//----------------------------------------------------------
63  
//----------------------------------------------------------
64  

64  

65  
// LCOV_EXCL_START
65  
// LCOV_EXCL_START
66  
void
66  
void
67  
static_url_base::
67  
static_url_base::
68  
cleanup(op_t&)
68  
cleanup(op_t&)
69  
{
69  
{
70  
    /*
70  
    /*
71  
     * The cleanup function is a blank
71  
     * The cleanup function is a blank
72  
     * override as it's unreachable
72  
     * override as it's unreachable
73  
     * for static_url_base.
73  
     * for static_url_base.
74  
     *
74  
     *
75  
     * `u.cleanup()` is called by `op_t` when
75  
     * `u.cleanup()` is called by `op_t` when
76  
     * the `op_t::old` string is being replaced.
76  
     * the `op_t::old` string is being replaced.
77  
     * This never happens for `static_url_base`
77  
     * This never happens for `static_url_base`
78  
     * because it always uses the same buffer.
78  
     * because it always uses the same buffer.
79  
     *
79  
     *
80  
     * `url::reserve_impl` is the only function
80  
     * `url::reserve_impl` is the only function
81  
     * that sets the `op_t::old` string but
81  
     * that sets the `op_t::old` string but
82  
     * `static_url_base::reserve_impl` does
82  
     * `static_url_base::reserve_impl` does
83  
     * not touch `op_t::old`.
83  
     * not touch `op_t::old`.
84  
     */
84  
     */
85  
}
85  
}
86  
// LCOV_EXCL_STOP
86  
// LCOV_EXCL_STOP
87  

87  

88  
} // urls
88  
} // urls
89  
} // boost
89  
} // boost
90  

90