| 1 |
|
|
1 |
|
|
| 2 |
|
// Copyright (c) 2025 Alan de Freitas (alandefreitas@gmail.com)
|
2 |
|
// Copyright (c) 2025 Alan de Freitas (alandefreitas@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_DECODE_HPP
|
10 |
|
#ifndef BOOST_URL_IMPL_DECODE_HPP
|
| 11 |
|
#define BOOST_URL_IMPL_DECODE_HPP
|
11 |
|
#define BOOST_URL_IMPL_DECODE_HPP
|
| 12 |
|
|
12 |
|
|
| 13 |
|
#include <boost/assert.hpp>
|
13 |
|
#include <boost/assert.hpp>
|
| 14 |
|
#include <boost/url/detail/decode.hpp>
|
14 |
|
#include <boost/url/detail/decode.hpp>
|
| 15 |
|
#include <boost/url/detail/string_view.hpp>
|
15 |
|
#include <boost/url/detail/string_view.hpp>
|
| 16 |
|
#include <boost/url/pct_string_view.hpp>
|
16 |
|
#include <boost/url/pct_string_view.hpp>
|
| 17 |
|
|
17 |
|
|
| 18 |
|
|
18 |
|
|
| 19 |
|
|
19 |
|
|
| 20 |
|
|
20 |
|
|
| 21 |
|
|
21 |
|
|
| 22 |
|
|
22 |
|
|
| 23 |
|
system::result<std::size_t>
|
23 |
|
system::result<std::size_t>
|
| 24 |
|
decoded_size(core::string_view s) noexcept
|
24 |
|
decoded_size(core::string_view s) noexcept
|
| 25 |
|
|
25 |
|
|
| 26 |
|
auto const rv = make_pct_string_view(s);
|
26 |
|
auto const rv = make_pct_string_view(s);
|
| 27 |
|
|
27 |
|
|
| 28 |
|
|
28 |
|
|
| 29 |
|
return rv->decoded_size();
|
29 |
|
return rv->decoded_size();
|
| 30 |
|
|
30 |
|
|
| 31 |
|
|
31 |
|
|
| 32 |
|
|
32 |
|
|
| 33 |
|
system::result<std::size_t>
|
33 |
|
system::result<std::size_t>
|
| 34 |
|
|
34 |
|
|
| 35 |
|
|
35 |
|
|
| 36 |
|
|
36 |
|
|
| 37 |
|
|
37 |
|
|
| 38 |
|
encoding_opts opt) noexcept
|
38 |
|
encoding_opts opt) noexcept
|
| 39 |
|
|
39 |
|
|
| 40 |
|
auto const rv = make_pct_string_view(s);
|
40 |
|
auto const rv = make_pct_string_view(s);
|
| 41 |
|
|
41 |
|
|
| 42 |
|
|
42 |
|
|
| 43 |
|
return detail::decode_unsafe(
|
43 |
|
return detail::decode_unsafe(
|
| 44 |
|
|
44 |
|
|
| 45 |
|
|
45 |
|
|
| 46 |
|
detail::to_sv(rv.value()),
|
46 |
|
detail::to_sv(rv.value()),
|
| 47 |
|
|
47 |
|
|
| 48 |
|
|
48 |
|
|
| 49 |
|
|
49 |
|
|
| 50 |
|
|
50 |
|
|
| 51 |
|
BOOST_URL_CONSTRAINT(string_token::StringToken) StringToken>
|
51 |
|
BOOST_URL_CONSTRAINT(string_token::StringToken) StringToken>
|
| 52 |
|
system::result<typename StringToken::result_type>
|
52 |
|
system::result<typename StringToken::result_type>
|
| 53 |
|
|
53 |
|
|
| 54 |
|
|
54 |
|
|
| 55 |
|
|
55 |
|
|
| 56 |
|
StringToken&& token) noexcept
|
56 |
|
StringToken&& token) noexcept
|
| 57 |
|
|
57 |
|
|
| 58 |
|
|
58 |
|
|
| 59 |
|
|
59 |
|
|
| 60 |
|
|
60 |
|
|
| 61 |
|
"Type requirements not met");
|
61 |
|
"Type requirements not met");
|
| 62 |
|
|
62 |
|
|
| 63 |
|
auto const rv = make_pct_string_view(s);
|
63 |
|
auto const rv = make_pct_string_view(s);
|
| 64 |
|
|
64 |
|
|
| 65 |
|
|
65 |
|
|
| 66 |
|
|
66 |
|
|
| 67 |
|
auto const n = rv->decoded_size();
|
67 |
|
auto const n = rv->decoded_size();
|
| 68 |
|
auto p = token.prepare(n);
|
68 |
|
auto p = token.prepare(n);
|
| 69 |
|
// Some tokens might hand back a null/invalid buffer for n == 0, so skip the
|
69 |
|
// Some tokens might hand back a null/invalid buffer for n == 0, so skip the
|
| 70 |
|
// decode call entirely in that case to avoid touching unspecified memory.
|
70 |
|
// decode call entirely in that case to avoid touching unspecified memory.
|
| 71 |
|
|
71 |
|
|
| 72 |
|
|
72 |
|
|
| 73 |
|
|
73 |
|
|
| 74 |
|
|
74 |
|
|
| 75 |
|
detail::to_sv(rv.value()),
|
75 |
|
detail::to_sv(rv.value()),
|
| 76 |
|
|
76 |
|
|
| 77 |
|
|
77 |
|
|
| 78 |
|
|
78 |
|
|
| 79 |
|
|
79 |
|
|
| 80 |
|
|
80 |
|
|
| 81 |
|
|
81 |
|
|
| 82 |
|
|
82 |
|
|
| 83 |
|
|
83 |
|
|