no_trailing_dot_policy rejects parsing exp, exp_n, nan, inf and rejects parsing a fractional part if detects ".Fmt". For Fmt = 'j', 's', 'o', 'n': 42.foo rule parses 42. 42.json rule parses 42 42..json rule parses 42. Reference: - https://github.com/Project-OSRM/osrm-backend/pull/2222#issuecomment-206206239
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#ifndef NEAREST_PARAMETERS_GRAMMAR_HPP
|
|
#define NEAREST_PARAMETERS_GRAMMAR_HPP
|
|
|
|
#include "engine/api/nearest_parameters.hpp"
|
|
|
|
//#define BOOST_SPIRIT_DEBUG
|
|
#include "server/api/base_parameters_grammar.hpp"
|
|
|
|
#include <boost/spirit/include/qi_action.hpp>
|
|
#include <boost/spirit/include/qi_grammar.hpp>
|
|
#include <boost/spirit/include/qi_lit.hpp>
|
|
#include <boost/spirit/include/qi_optional.hpp>
|
|
#include <boost/spirit/include/qi_uint.hpp>
|
|
|
|
namespace osrm
|
|
{
|
|
namespace server
|
|
{
|
|
namespace api
|
|
{
|
|
|
|
namespace qi = boost::spirit::qi;
|
|
|
|
struct NearestParametersGrammar final : public BaseParametersGrammar
|
|
{
|
|
using Iterator = std::string::iterator;
|
|
|
|
NearestParametersGrammar() : BaseParametersGrammar(root_rule, parameters)
|
|
{
|
|
const auto set_number = [this](const unsigned number) {
|
|
parameters.number_of_results = number;
|
|
};
|
|
nearest_rule = (qi::lit("number=") >> qi::uint_)[set_number];
|
|
root_rule = query_rule >> -qi::lit(".json") >> -(qi::lit("?") >> (nearest_rule | base_rule) % '&');
|
|
}
|
|
|
|
engine::api::NearestParameters parameters;
|
|
|
|
private:
|
|
qi::rule<Iterator> root_rule;
|
|
qi::rule<Iterator> nearest_rule;
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|