Skip to content

Backport fix for #163 into 0.11.0 #369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Backport fix for #163 into 0.11.0
  • Loading branch information
deanberris committed Jan 20, 2014
commit bbf431c7d7daa7555dff1cc1e04c760f10336cb9
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