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

10  

10  

11  

11  
#include <boost/url/detail/config.hpp>
12  
#include <boost/url/detail/config.hpp>
12 -
#include "../rfc/detail/charsets.hpp"
13 +
#include <boost/url/rfc/detail/charsets.hpp>
13  
#include <boost/url/detail/any_segments_iter.hpp>
14  
#include <boost/url/detail/any_segments_iter.hpp>
14  
#include <boost/core/detail/string_view.hpp>
15  
#include <boost/core/detail/string_view.hpp>
15  
#include <boost/url/encode.hpp>
16  
#include <boost/url/encode.hpp>
16  
#include <boost/url/rfc/pchars.hpp>
17  
#include <boost/url/rfc/pchars.hpp>
17  

18  

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

22  

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

28  

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

37  

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

44  

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

63  

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

81  

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

87  

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

104  

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

124  

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

130  

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

139  

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

146  

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

162  

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

177  

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

183  

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

197  

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

214  

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

218