Skip to content

Commit

Permalink
Backport fix for cpp-netlib#163 into 0.11.0
Browse files Browse the repository at this point in the history
  • Loading branch information
deanberris committed Jan 20, 2014
1 parent f2daa26 commit 25083c1
Show file tree
Hide file tree
Showing 3 changed files with 367 additions and 329 deletions.
4 changes: 2 additions & 2 deletions boost/network/uri/accessors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ struct key_value_sequence
{
query = pair >> *((spirit::qi::lit(';') | '&') >> pair);
pair = key >> -('=' >> value);
key = spirit::qi::char_("a-zA-Z_") >> *spirit::qi::char_("a-zA-Z_0-9/%");
value = +spirit::qi::char_("a-zA-Z_0-9/%");
key = spirit::qi::char_("a-zA-Z_") >> *spirit::qi::char_("-+.~a-zA-Z_0-9/%");
value = +spirit::qi::char_("-+.~a-zA-Z_0-9/%");
}

spirit::qi::rule<uri::const_iterator, Map()> query;
Expand Down
106 changes: 45 additions & 61 deletions boost/network/uri/decode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,21 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)


#ifndef __BOOST_NETWORK_URI_DECODE_INC__
# define __BOOST_NETWORK_URI_DECODE_INC__


# include <boost/iterator/iterator_traits.hpp>
# include <boost/range/begin.hpp>
# include <boost/range/end.hpp>
# include <cassert>
#define __BOOST_NETWORK_URI_DECODE_INC__

#include <boost/iterator/iterator_traits.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <cassert>

namespace boost {
namespace network {
namespace uri {
namespace detail {
template <
typename CharT
>
CharT letter_to_hex(CharT in)
{
switch (in)
{
template <typename CharT>
CharT letter_to_hex(CharT in) {
switch (in) {
case '0':
case '1':
case '2':
Expand All @@ -35,74 +28,65 @@ CharT letter_to_hex(CharT in)
case '7':
case '8':
case '9':
return in - '0';
return in - '0';
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
return in + 10 - 'a';
return in + 10 - 'a';
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
return in + 10 - 'A';
}
return CharT();
return in + 10 - 'A';
}
return CharT();
}
} // namespace detail
} // namespace detail

template <
class InputIterator,
class OutputIterator
>
template <class InputIterator, class OutputIterator>
OutputIterator decode(const InputIterator &in_begin,
const InputIterator &in_end,
const OutputIterator &out_begin) {
typedef typename boost::iterator_value<InputIterator>::type value_type;
typedef typename boost::iterator_value<InputIterator>::type value_type;

InputIterator it = in_begin;
OutputIterator out = out_begin;
while (it != in_end) {
if (*it == '%')
{
++it;
value_type v0 = detail::letter_to_hex(*it);
++it;
value_type v1 = detail::letter_to_hex(*it);
++it;
*out++ = 0x10 * v0 + v1;
}
else
{
*out++ = *it++;
}
InputIterator it = in_begin;
OutputIterator out = out_begin;
while (it != in_end) {
if (*it == '%') {
++it;
value_type v0 = detail::letter_to_hex(*it);
++it;
value_type v1 = detail::letter_to_hex(*it);
++it;
*out++ = 0x10 * v0 + v1;
} else if (*it == '+') {
*out++ = ' ';
++it;
} else {
*out++ = *it++;
}
return out;
}
return out;
}

template <
class SinglePassRange,
class OutputIterator
>
inline
OutputIterator decode(const SinglePassRange &range,
const OutputIterator &out) {
return decode(boost::begin(range), boost::end(range), out);
template <class SinglePassRange, class OutputIterator>
inline OutputIterator decode(const SinglePassRange &range,
const OutputIterator &out) {
return decode(boost::begin(range), boost::end(range), out);
}

inline
std::string decoded(const std::string &input) {
std::string decoded;
decode(input, std::back_inserter(decoded));
return decoded;
inline std::string decoded(const std::string &input) {
std::string decoded;
decode(input, std::back_inserter(decoded));
return decoded;
}
} // namespace uri
} // namespace network
} // namespace boost

} // namespace uri
} // namespace network
} // namespace boost

#endif // __BOOST_NETWORK_URI_DECODE_INC__
#endif // __BOOST_NETWORK_URI_DECODE_INC__
Loading

0 comments on commit 25083c1

Please sign in to comment.