3
3
// (See accompanying file LICENSE_1_0.txt or copy at
4
4
// http://www.boost.org/LICENSE_1_0.txt)
5
5
6
-
7
6
#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__
15
8
9
+ #include < boost/iterator/iterator_traits.hpp>
10
+ #include < boost/range/begin.hpp>
11
+ #include < boost/range/end.hpp>
12
+ #include < cassert>
16
13
17
14
namespace boost {
18
15
namespace network {
19
16
namespace uri {
20
17
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) {
28
21
case ' 0' :
29
22
case ' 1' :
30
23
case ' 2' :
@@ -35,74 +28,65 @@ CharT letter_to_hex(CharT in)
35
28
case ' 7' :
36
29
case ' 8' :
37
30
case ' 9' :
38
- return in - ' 0' ;
31
+ return in - ' 0' ;
39
32
case ' a' :
40
33
case ' b' :
41
34
case ' c' :
42
35
case ' d' :
43
36
case ' e' :
44
37
case ' f' :
45
- return in + 10 - ' a' ;
38
+ return in + 10 - ' a' ;
46
39
case ' A' :
47
40
case ' B' :
48
41
case ' C' :
49
42
case ' D' :
50
43
case ' E' :
51
44
case ' F' :
52
- return in + 10 - ' A' ;
53
- }
54
- return CharT ();
45
+ return in + 10 - ' A' ;
46
+ }
47
+ return CharT ();
55
48
}
56
- } // namespace detail
49
+ } // namespace detail
57
50
58
- template <
59
- class InputIterator ,
60
- class OutputIterator
61
- >
51
+ template <class InputIterator , class OutputIterator >
62
52
OutputIterator decode (const InputIterator &in_begin,
63
53
const InputIterator &in_end,
64
54
const OutputIterator &out_begin) {
65
- typedef typename boost::iterator_value<InputIterator>::type value_type;
55
+ typedef typename boost::iterator_value<InputIterator>::type value_type;
66
56
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++;
83
72
}
84
- return out;
73
+ }
74
+ return out;
85
75
}
86
76
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);
95
81
}
96
82
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;
102
87
}
103
- } // namespace uri
104
- } // namespace network
105
- } // namespace boost
106
-
88
+ } // namespace uri
89
+ } // namespace network
90
+ } // namespace boost
107
91
108
- #endif // __BOOST_NETWORK_URI_DECODE_INC__
92
+ #endif // __BOOST_NETWORK_URI_DECODE_INC__
0 commit comments