Skip to content

Commit 25083c1

Browse files
committed
Backport fix for cpp-netlib#163 into 0.11.0
1 parent f2daa26 commit 25083c1

File tree

3 files changed

+367
-329
lines changed

3 files changed

+367
-329
lines changed

boost/network/uri/accessors.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ struct key_value_sequence
3434
{
3535
query = pair >> *((spirit::qi::lit(';') | '&') >> pair);
3636
pair = key >> -('=' >> value);
37-
key = spirit::qi::char_("a-zA-Z_") >> *spirit::qi::char_("a-zA-Z_0-9/%");
38-
value = +spirit::qi::char_("a-zA-Z_0-9/%");
37+
key = spirit::qi::char_("a-zA-Z_") >> *spirit::qi::char_("-+.~a-zA-Z_0-9/%");
38+
value = +spirit::qi::char_("-+.~a-zA-Z_0-9/%");
3939
}
4040

4141
spirit::qi::rule<uri::const_iterator, Map()> query;

boost/network/uri/decode.hpp

Lines changed: 45 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,21 @@
33
// (See accompanying file LICENSE_1_0.txt or copy at
44
// http://www.boost.org/LICENSE_1_0.txt)
55

6-
76
#ifndef __BOOST_NETWORK_URI_DECODE_INC__
8-
# define __BOOST_NETWORK_URI_DECODE_INC__
9-
10-
11-
# include <boost/iterator/iterator_traits.hpp>
12-
# include <boost/range/begin.hpp>
13-
# include <boost/range/end.hpp>
14-
# include <cassert>
7+
#define __BOOST_NETWORK_URI_DECODE_INC__
158

9+
#include <boost/iterator/iterator_traits.hpp>
10+
#include <boost/range/begin.hpp>
11+
#include <boost/range/end.hpp>
12+
#include <cassert>
1613

1714
namespace boost {
1815
namespace network {
1916
namespace uri {
2017
namespace detail {
21-
template <
22-
typename CharT
23-
>
24-
CharT letter_to_hex(CharT in)
25-
{
26-
switch (in)
27-
{
18+
template <typename CharT>
19+
CharT letter_to_hex(CharT in) {
20+
switch (in) {
2821
case '0':
2922
case '1':
3023
case '2':
@@ -35,74 +28,65 @@ CharT letter_to_hex(CharT in)
3528
case '7':
3629
case '8':
3730
case '9':
38-
return in - '0';
31+
return in - '0';
3932
case 'a':
4033
case 'b':
4134
case 'c':
4235
case 'd':
4336
case 'e':
4437
case 'f':
45-
return in + 10 - 'a';
38+
return in + 10 - 'a';
4639
case 'A':
4740
case 'B':
4841
case 'C':
4942
case 'D':
5043
case 'E':
5144
case 'F':
52-
return in + 10 - 'A';
53-
}
54-
return CharT();
45+
return in + 10 - 'A';
46+
}
47+
return CharT();
5548
}
56-
} // namespace detail
49+
} // namespace detail
5750

58-
template <
59-
class InputIterator,
60-
class OutputIterator
61-
>
51+
template <class InputIterator, class OutputIterator>
6252
OutputIterator decode(const InputIterator &in_begin,
6353
const InputIterator &in_end,
6454
const OutputIterator &out_begin) {
65-
typedef typename boost::iterator_value<InputIterator>::type value_type;
55+
typedef typename boost::iterator_value<InputIterator>::type value_type;
6656

67-
InputIterator it = in_begin;
68-
OutputIterator out = out_begin;
69-
while (it != in_end) {
70-
if (*it == '%')
71-
{
72-
++it;
73-
value_type v0 = detail::letter_to_hex(*it);
74-
++it;
75-
value_type v1 = detail::letter_to_hex(*it);
76-
++it;
77-
*out++ = 0x10 * v0 + v1;
78-
}
79-
else
80-
{
81-
*out++ = *it++;
82-
}
57+
InputIterator it = in_begin;
58+
OutputIterator out = out_begin;
59+
while (it != in_end) {
60+
if (*it == '%') {
61+
++it;
62+
value_type v0 = detail::letter_to_hex(*it);
63+
++it;
64+
value_type v1 = detail::letter_to_hex(*it);
65+
++it;
66+
*out++ = 0x10 * v0 + v1;
67+
} else if (*it == '+') {
68+
*out++ = ' ';
69+
++it;
70+
} else {
71+
*out++ = *it++;
8372
}
84-
return out;
73+
}
74+
return out;
8575
}
8676

87-
template <
88-
class SinglePassRange,
89-
class OutputIterator
90-
>
91-
inline
92-
OutputIterator decode(const SinglePassRange &range,
93-
const OutputIterator &out) {
94-
return decode(boost::begin(range), boost::end(range), out);
77+
template <class SinglePassRange, class OutputIterator>
78+
inline OutputIterator decode(const SinglePassRange &range,
79+
const OutputIterator &out) {
80+
return decode(boost::begin(range), boost::end(range), out);
9581
}
9682

97-
inline
98-
std::string decoded(const std::string &input) {
99-
std::string decoded;
100-
decode(input, std::back_inserter(decoded));
101-
return decoded;
83+
inline std::string decoded(const std::string &input) {
84+
std::string decoded;
85+
decode(input, std::back_inserter(decoded));
86+
return decoded;
10287
}
103-
} // namespace uri
104-
} // namespace network
105-
} // namespace boost
106-
88+
} // namespace uri
89+
} // namespace network
90+
} // namespace boost
10791

108-
#endif // __BOOST_NETWORK_URI_DECODE_INC__
92+
#endif // __BOOST_NETWORK_URI_DECODE_INC__

0 commit comments

Comments
 (0)