From 3552443896cf1fc9c5e484ee888811838bfca966 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Wed, 22 May 2024 18:07:59 +0200 Subject: [PATCH] wip --- src/server/api/url_parser.cpp | 82 +++++++++++++++++------------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/server/api/url_parser.cpp b/src/server/api/url_parser.cpp index ef19809dd..d217a3bcc 100644 --- a/src/server/api/url_parser.cpp +++ b/src/server/api/url_parser.cpp @@ -2,65 +2,65 @@ #include "engine/polyline_compressor.hpp" #include -#include -#include -#include #include +#include +#include +#include #include BOOST_FUSION_ADAPT_STRUCT(osrm::server::api::ParsedURL, - (std::string, service) - (unsigned, version) - (std::string, profile) - (std::string, query)) + (std::string, service)(unsigned, version)(std::string, + profile)(std::string, query)) namespace osrm::server::api { - namespace x3 = boost::spirit::x3; +namespace x3 = boost::spirit::x3; - struct ParsedURLClass : x3::annotate_on_success {}; - const x3::rule service = "service"; - const x3::rule version = "version"; - const x3::rule profile = "profile"; - const x3::rule query = "query"; - const x3::rule start = "start"; +struct ParsedURLClass : x3::annotate_on_success +{ +}; +const x3::rule service = "service"; +const x3::rule version = "version"; +const x3::rule profile = "profile"; +const x3::rule query = "query"; +const x3::rule start = "start"; - const auto identifier = x3::char_("a-zA-Z0-9_.~:-"); - const auto percent_encoding = x3::char_('%') >> x3::uint_parser(); - const auto polyline_chars = x3::char_("a-zA-Z0-9_[]{}@?|\\~`^") | percent_encoding; - const auto all_chars = polyline_chars | x3::char_("=,;:&().-"); +const auto identifier = x3::char_("a-zA-Z0-9_.~:-"); +const auto percent_encoding = x3::char_('%') >> x3::uint_parser(); +const auto polyline_chars = x3::char_("a-zA-Z0-9_[]{}@?|\\~`^") | percent_encoding; +const auto all_chars = polyline_chars | x3::char_("=,;:&().-"); - const auto service_def = +identifier; - const auto version_def = x3::uint_; - const auto profile_def = +identifier; - const auto query_def = +all_chars; +const auto service_def = +identifier; +const auto version_def = x3::uint_; +const auto profile_def = +identifier; +const auto query_def = +all_chars; - const auto start_def = - x3::lit('/') > service > x3::lit('/') > x3::lit('v') > version > x3::lit('/') > profile > x3::lit('/') > query; +const auto start_def = x3::lit('/') > service > x3::lit('/') > x3::lit('v') > version + > x3::lit('/') > profile > x3::lit('/') > query; - BOOST_SPIRIT_DEFINE(service, version, profile, query, start) +BOOST_SPIRIT_DEFINE(service, version, profile, query, start) - boost::optional parseURL(std::string::iterator &iter, const std::string::iterator end) +boost::optional parseURL(std::string::iterator &iter, const std::string::iterator end) +{ + ParsedURL out; + + try { - ParsedURL out; + auto iter_copy = iter; + bool r = x3::phrase_parse(iter_copy, end, start, x3::space, out); - try + if (r && iter_copy == end) { - auto iter_copy = iter; - bool r = x3::phrase_parse(iter_copy, end, start, x3::space, out); - - if (r && iter_copy == end) - { - iter = iter_copy; - return boost::make_optional(out); - } + iter = iter_copy; + return boost::make_optional(out); } - catch (const x3::expectation_failure &) - { - } - - return boost::none; + } + catch (const x3::expectation_failure &) + { } + return boost::none; +} + } // namespace osrm::server::api