Skip to content

Commit 1ece316

Browse files
committed
Fixing the parser to use the correct transforms.
1 parent 7b383aa commit 1ece316

File tree

1 file changed

+109
-9
lines changed

1 file changed

+109
-9
lines changed

libs/network/src/parse_uri_impl.cpp

Lines changed: 109 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,98 @@ BOOST_FUSION_ADAPT_STRUCT(boost::network::uri::detail::uri_parts_wide_base,
4141
(optional<std::wstring>, fragment)
4242
)
4343

44+
namespace boost { namespace spirit { namespace traits {
45+
template <>
46+
struct transform_attribute<
47+
boost::network::uri::detail::uri_parts_default_base,
48+
boost::fusion::tuple<
49+
std::string &,
50+
boost::fusion::tuple<
51+
boost::optional<std::string>&,
52+
boost::optional<std::string>&,
53+
boost::optional<boost::uint16_t> &,
54+
std::string &
55+
>,
56+
optional<std::string>&,
57+
optional<std::string>&
58+
>
59+
#if SPIRIT_VERSION >= 0x2030
60+
, boost::spirit::qi::domain
61+
#endif
62+
>
63+
{
64+
typedef
65+
boost::fusion::tuple<
66+
std::string &,
67+
boost::fusion::tuple<
68+
boost::optional<std::string>&,
69+
boost::optional<std::string>&,
70+
boost::optional<boost::uint16_t> &,
71+
std::string &
72+
>,
73+
optional<std::string>&,
74+
optional<std::string>&
75+
> type;
76+
77+
static type pre(boost::network::uri::detail::uri_parts_default_base & parts) {
78+
boost::fusion::tuple<
79+
boost::optional<std::string> &,
80+
boost::optional<std::string> &,
81+
boost::optional<boost::uint16_t> &,
82+
std::string &
83+
> hier_part =
84+
boost::fusion::tie(
85+
parts.user_info,
86+
parts.host,
87+
parts.port,
88+
parts.path
89+
);
90+
91+
return boost::fusion::tie(
92+
parts.scheme,
93+
hier_part,
94+
parts.query,
95+
parts.fragment
96+
);
97+
}
98+
99+
static void post(boost::network::uri::detail::uri_parts_default_base &, type const &) { }
100+
101+
#if SPIRIT_VERSION >= 0x2030
102+
static void fail(boost::network::uri::detail::uri_parts_default_base & val) { }
103+
#endif
104+
};
105+
106+
#if SPIRIT_VERSION < 0x2030
107+
template <typename Exposed, typename Transformed>
108+
struct transform_attribute<
109+
optional<Exposed>,
110+
Transformed,
111+
typename disable_if<is_same<optional<Exposed>, Transformed> >::type
112+
>
113+
{
114+
typedef Transformed & type;
115+
116+
static Transformed & pre(optional<Exposed> & val) {
117+
if (!val)
118+
val = Transformed();
119+
return boost::get<Transformed>(val);
120+
}
121+
122+
static void post(optional<Exposed> &, Transformed const &) { }
123+
};
124+
#endif
125+
} // namespace traits
126+
} // namespace spirit
127+
} // namespace boost
128+
129+
44130
namespace boost { namespace network { namespace uri { namespace detail {
45131

46132
namespace qi = boost::spirit::qi;
47133

48134
template <typename Iterator>
49-
struct uri_grammar_default : qi::grammar<Iterator, uri_parts_default_base> {
135+
struct uri_grammar_default : qi::grammar<Iterator, uri_parts_default_base()> {
50136
uri_grammar_default() : uri_grammar_default::base_type(start, "uri") {
51137
// gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
52138
gen_delims %= qi::char_(":/?#[]@");
@@ -166,17 +252,31 @@ struct uri_grammar_default : qi::grammar<Iterator, uri_parts_default_base> {
166252
scheme, user_info, query, fragment;
167253

168254
qi::rule<Iterator, boost::fusion::tuple<
169-
optional<string_type>,
170-
optional<string_type>,
171-
optional<boost::uint16_t>,
172-
string_type
255+
optional<string_type>&,
256+
optional<string_type>&,
257+
optional<boost::uint16_t>&,
258+
string_type &
173259
>()> hier_part;
174260

175-
// start rule of grammar
176-
qi::rule<Iterator, uri_parts_default_base> start;
261+
// start rule of grammar
262+
qi::rule<Iterator, uri_parts_default_base()> start;
263+
264+
// actual uri parser
265+
qi::rule<
266+
Iterator,
267+
boost::fusion::tuple<
268+
string_type&,
269+
boost::fusion::tuple<
270+
optional<string_type>&,
271+
optional<string_type>&,
272+
optional<boost::uint16_t>&,
273+
string_type &
274+
>,
275+
optional<string_type>&,
276+
optional<string_type>&
277+
>()
278+
> uri;
177279

178-
// actual uri parser
179-
qi::rule<Iterator, uri_parts_default_base> uri;
180280
};
181281

182282
bool parse_uri_impl(boost::iterator_range<std::string::const_iterator> & range, uri_parts_default_base & parts, boost::network::tags::default_string) {

0 commit comments

Comments
 (0)