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 "../rfc/detail/charsets.hpp"
12  
#include "../rfc/detail/charsets.hpp"
13  
#include <boost/url/detail/any_segments_iter.hpp>
13  
#include <boost/url/detail/any_segments_iter.hpp>
14  
#include <boost/core/detail/string_view.hpp>
14  
#include <boost/core/detail/string_view.hpp>
15  
#include <boost/url/encode.hpp>
15  
#include <boost/url/encode.hpp>
16  
#include <boost/url/rfc/pchars.hpp>
16  
#include <boost/url/rfc/pchars.hpp>
17  

17  

18  
namespace boost {
18  
namespace boost {
19  
namespace urls {
19  
namespace urls {
20  
namespace detail {
20  
namespace detail {
21  

21  

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

27  

28  
segment_iter::
28  
segment_iter::
29  
segment_iter(
29  
segment_iter(
30  
    core::string_view s_) noexcept
30  
    core::string_view s_) noexcept
31  
    : any_segments_iter(s_)
31  
    : any_segments_iter(s_)
32  
{
32  
{
33  
    front = s;
33  
    front = s;
34  
    fast_nseg = 1;
34  
    fast_nseg = 1;
35  
}
35  
}
36  

36  

37  
void
37  
void
38  
segment_iter::
38  
segment_iter::
39  
rewind() noexcept
39  
rewind() noexcept
40  
{
40  
{
41  
    at_end_ = false;
41  
    at_end_ = false;
42  
}
42  
}
43  

43  

44  
bool
44  
bool
45  
segment_iter::
45  
segment_iter::
46  
measure(
46  
measure(
47  
    std::size_t& n) noexcept
47  
    std::size_t& n) noexcept
48  
{
48  
{
49  
    if(at_end_)
49  
    if(at_end_)
50  
        return false;
50  
        return false;
51  
    encoding_opts opt;
51  
    encoding_opts opt;
52  
    opt.space_as_plus = false;
52  
    opt.space_as_plus = false;
53  
    n += encoded_size(
53  
    n += encoded_size(
54  
        s,
54  
        s,
55  
        encode_colons ?
55  
        encode_colons ?
56  
            nocolon_pchars :
56  
            nocolon_pchars :
57  
            pchars,
57  
            pchars,
58  
        opt);
58  
        opt);
59  
    at_end_ = true;
59  
    at_end_ = true;
60  
    return true;
60  
    return true;
61  
}
61  
}
62  

62  

63  
void
63  
void
64  
segment_iter::
64  
segment_iter::
65  
copy(
65  
copy(
66  
    char*& dest,
66  
    char*& dest,
67  
    char const* end) noexcept
67  
    char const* end) noexcept
68  
{
68  
{
69  
    encoding_opts opt;
69  
    encoding_opts opt;
70  
    opt.space_as_plus = false;
70  
    opt.space_as_plus = false;
71  
    dest += encode(
71  
    dest += encode(
72  
        dest,
72  
        dest,
73  
        end - dest,
73  
        end - dest,
74  
        s,
74  
        s,
75  
        encode_colons ?
75  
        encode_colons ?
76  
            nocolon_pchars :
76  
            nocolon_pchars :
77  
            pchars,
77  
            pchars,
78  
        opt);
78  
        opt);
79  
}
79  
}
80  

80  

81  
//------------------------------------------------
81  
//------------------------------------------------
82  
//
82  
//
83  
// segments_iter_base
83  
// segments_iter_base
84  
//
84  
//
85  
//------------------------------------------------
85  
//------------------------------------------------
86  

86  

87  
void
87  
void
88  
segments_iter_base::
88  
segments_iter_base::
89  
measure_impl(
89  
measure_impl(
90  
    std::size_t& n,
90  
    std::size_t& n,
91  
    core::string_view s,
91  
    core::string_view s,
92  
    bool encode_colons) noexcept
92  
    bool encode_colons) noexcept
93  
{
93  
{
94  
    encoding_opts opt;
94  
    encoding_opts opt;
95  
    opt.space_as_plus = false;
95  
    opt.space_as_plus = false;
96  
    n += encoded_size(
96  
    n += encoded_size(
97  
        s,
97  
        s,
98  
        encode_colons ?
98  
        encode_colons ?
99  
            nocolon_pchars :
99  
            nocolon_pchars :
100  
            pchars,
100  
            pchars,
101  
        opt);
101  
        opt);
102  
}
102  
}
103  

103  

104  
void
104  
void
105  
segments_iter_base::
105  
segments_iter_base::
106  
copy_impl(
106  
copy_impl(
107  
    char*& dest,
107  
    char*& dest,
108  
    char const* end,
108  
    char const* end,
109  
    core::string_view s,
109  
    core::string_view s,
110  
    bool encode_colons) noexcept
110  
    bool encode_colons) noexcept
111  
{
111  
{
112  
    encoding_opts opt;
112  
    encoding_opts opt;
113  
    opt.space_as_plus = false;
113  
    opt.space_as_plus = false;
114  
    dest += encode(
114  
    dest += encode(
115  
        dest,
115  
        dest,
116  
        end - dest,
116  
        end - dest,
117  
        s,
117  
        s,
118  
        encode_colons ?
118  
        encode_colons ?
119  
            nocolon_pchars :
119  
            nocolon_pchars :
120  
            pchars,
120  
            pchars,
121  
        opt);
121  
        opt);
122  
}
122  
}
123  

123  

124  
//------------------------------------------------
124  
//------------------------------------------------
125  
//
125  
//
126  
// segment_encoded_iter
126  
// segment_encoded_iter
127  
//
127  
//
128  
//------------------------------------------------
128  
//------------------------------------------------
129  

129  

130  
segment_encoded_iter::
130  
segment_encoded_iter::
131  
segment_encoded_iter(
131  
segment_encoded_iter(
132  
    pct_string_view const& s_) noexcept
132  
    pct_string_view const& s_) noexcept
133  
    : any_segments_iter(s_)
133  
    : any_segments_iter(s_)
134  
{
134  
{
135  
    front = s;
135  
    front = s;
136  
    fast_nseg = 1;
136  
    fast_nseg = 1;
137  
}
137  
}
138  

138  

139  
void
139  
void
140  
segment_encoded_iter::
140  
segment_encoded_iter::
141  
rewind() noexcept
141  
rewind() noexcept
142  
{
142  
{
143  
    at_end_ = false;
143  
    at_end_ = false;
144  
}
144  
}
145  

145  

146  
bool
146  
bool
147  
segment_encoded_iter::
147  
segment_encoded_iter::
148  
measure(
148  
measure(
149  
    std::size_t& n) noexcept
149  
    std::size_t& n) noexcept
150  
{
150  
{
151  
    if(at_end_)
151  
    if(at_end_)
152  
        return false;
152  
        return false;
153  
    n += detail::re_encoded_size_unsafe(
153  
    n += detail::re_encoded_size_unsafe(
154  
        s,
154  
        s,
155  
        encode_colons ?
155  
        encode_colons ?
156  
            nocolon_pchars :
156  
            nocolon_pchars :
157  
            pchars);
157  
            pchars);
158  
    at_end_ = true;
158  
    at_end_ = true;
159  
    return true;
159  
    return true;
160  
}
160  
}
161  

161  

162  
void
162  
void
163  
segment_encoded_iter::
163  
segment_encoded_iter::
164  
copy(
164  
copy(
165  
    char*& dest,
165  
    char*& dest,
166  
    char const* end) noexcept
166  
    char const* end) noexcept
167  
{
167  
{
168  
    detail::re_encode_unsafe(
168  
    detail::re_encode_unsafe(
169  
        dest,
169  
        dest,
170  
        end,
170  
        end,
171  
        s,
171  
        s,
172  
        encode_colons ?
172  
        encode_colons ?
173  
            nocolon_pchars :
173  
            nocolon_pchars :
174  
            pchars);
174  
            pchars);
175  
}
175  
}
176  

176  

177  
//------------------------------------------------
177  
//------------------------------------------------
178  
//
178  
//
179  
// segments_encoded_iter_base
179  
// segments_encoded_iter_base
180  
//
180  
//
181  
//------------------------------------------------
181  
//------------------------------------------------
182  

182  

183  
void
183  
void
184  
segments_encoded_iter_base::
184  
segments_encoded_iter_base::
185  
measure_impl(
185  
measure_impl(
186  
    std::size_t& n,
186  
    std::size_t& n,
187  
    core::string_view s,
187  
    core::string_view s,
188  
    bool encode_colons) noexcept
188  
    bool encode_colons) noexcept
189  
{
189  
{
190  
    n += detail::re_encoded_size_unsafe(
190  
    n += detail::re_encoded_size_unsafe(
191  
        s,
191  
        s,
192  
        encode_colons ?
192  
        encode_colons ?
193  
            nocolon_pchars :
193  
            nocolon_pchars :
194  
            pchars);
194  
            pchars);
195  
}
195  
}
196  

196  

197  
void
197  
void
198  
segments_encoded_iter_base::
198  
segments_encoded_iter_base::
199  
copy_impl(
199  
copy_impl(
200  
    char*& dest,
200  
    char*& dest,
201  
    char const* end,
201  
    char const* end,
202  
    core::string_view s,
202  
    core::string_view s,
203  
    bool encode_colons) noexcept
203  
    bool encode_colons) noexcept
204  
{
204  
{
205  
    detail::re_encode_unsafe(
205  
    detail::re_encode_unsafe(
206  
        dest,
206  
        dest,
207  
        end,
207  
        end,
208  
        s,
208  
        s,
209  
        encode_colons ?
209  
        encode_colons ?
210  
            nocolon_pchars :
210  
            nocolon_pchars :
211  
            pchars);
211  
            pchars);
212  
}
212  
}
213  

213  

214  
} // detail
214  
} // detail
215  
} // urls
215  
} // urls
216  
} // boost
216  
} // boost
217  

217