2016-02-03 07:18:20 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2016-02-04 09:45:12 +08:00
|
|
|
#include <tuple>
|
|
|
|
#include <utility>
|
2016-02-03 07:18:20 +08:00
|
|
|
|
|
|
|
#include "cypher/cypher.h"
|
2016-02-04 09:45:12 +08:00
|
|
|
#include "cypher/tokenizer/cypher_lexer.hpp"
|
|
|
|
#include "utils/variadic/variadic.hpp"
|
2016-02-03 07:18:20 +08:00
|
|
|
|
2016-02-04 09:45:12 +08:00
|
|
|
template<typename ...Ts>
|
2016-02-03 07:18:20 +08:00
|
|
|
class QueryStripper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2016-02-04 09:45:12 +08:00
|
|
|
QueryStripper(Ts&&... strip_types)
|
|
|
|
: strip_types(std::make_tuple(std::forward<Ts>(strip_types)...)) {}
|
2016-02-03 07:18:20 +08:00
|
|
|
|
|
|
|
std::string strip(const std::string& query)
|
|
|
|
{
|
|
|
|
auto tokenizer = lexer.tokenize(query);
|
|
|
|
std::string stripped = "";
|
|
|
|
int counter = 0;
|
2016-02-04 09:45:12 +08:00
|
|
|
constexpr auto size = std::tuple_size<decltype(strip_types)>::value;
|
2016-02-03 07:18:20 +08:00
|
|
|
while (auto token = tokenizer.lookup())
|
|
|
|
{
|
2016-02-04 09:45:12 +08:00
|
|
|
if (_or(token.id, strip_types, std::make_index_sequence<size>{})) {
|
2016-02-03 07:18:20 +08:00
|
|
|
stripped += "@" + std::to_string(counter++);
|
|
|
|
} else {
|
|
|
|
stripped += token.value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stripped;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-02-04 09:45:12 +08:00
|
|
|
std::tuple<Ts...> strip_types;
|
2016-02-03 07:18:20 +08:00
|
|
|
CypherLexer lexer;
|
2016-02-04 09:45:12 +08:00
|
|
|
|
|
|
|
template<typename Value, typename Tuple, std::size_t ...index>
|
|
|
|
bool _or(Value&& value, Tuple&& tuple, std::index_sequence<index...>)
|
|
|
|
{
|
|
|
|
return or_vargs(std::forward<Value>(value),
|
|
|
|
std::get<index>(std::forward<Tuple>(tuple))...);
|
|
|
|
}
|
2016-02-03 07:18:20 +08:00
|
|
|
};
|