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  
#ifndef BOOST_URL_IMPL_STATIC_URL_HPP
10  
#ifndef BOOST_URL_IMPL_STATIC_URL_HPP
11  
#define BOOST_URL_IMPL_STATIC_URL_HPP
11  
#define BOOST_URL_IMPL_STATIC_URL_HPP
12  

12  

13  
#include <boost/url/detail/except.hpp>
13  
#include <boost/url/detail/except.hpp>
14  
#include <boost/assert.hpp>
14  
#include <boost/assert.hpp>
15  

15  

16  
namespace boost {
16  
namespace boost {
17  
namespace urls {
17  
namespace urls {
18  

18  

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

30  

31  
inline
31  
inline
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  
inline
43  
inline
44  
void
44  
void
45  
static_url_base::
45  
static_url_base::
46  
clear_impl() noexcept
46  
clear_impl() noexcept
47  
{
47  
{
48  
    impl_ = {from::url};
48  
    impl_ = {from::url};
49  
    s_[0] = '\0';
49  
    s_[0] = '\0';
50  
    impl_.cs_ = s_;
50  
    impl_.cs_ = s_;
51  
}
51  
}
52  

52  

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

64  

65  
//----------------------------------------------------------
65  
//----------------------------------------------------------
66  

66  

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

90  

91  
} // urls
91  
} // urls
92  
} // boost
92  
} // boost
93  

93  

94  
#endif
94  
#endif