#pragma once #include #include #include #include "cypher/cypher.h" #include "cypher/tokenizer/cypher_lexer.hpp" #include "utils/variadic/variadic.hpp" #include template class QueryStripper { public: QueryStripper(Ts&&... strip_types) : lexer(std::make_unique()), strip_types(std::make_tuple(std::forward(strip_types)...)) { } QueryStripper(QueryStripper& other) = delete; QueryStripper(QueryStripper&& other) : strip_types(std::move(other.strip_types)), lexer(std::move(other.lexer)) { } decltype(auto) strip(const std::string& query) { auto tokenizer = lexer->tokenize(query); std::string stripped = ""; int counter = 0; constexpr auto size = std::tuple_size::value; while (auto token = tokenizer.lookup()) { if (_or(token.id, strip_types, std::make_index_sequence{})) { stripped += "@" + std::to_string(counter++); } else { stripped += token.value; } } return stripped; } private: std::tuple strip_types; CypherLexer::uptr lexer; template bool _or(Value&& value, Tuple&& tuple, std::index_sequence) { return or_vargs(std::forward(value), std::get(std::forward(tuple))...); } }; template decltype(auto) make_query_stripper(Ts&&... ts) { return QueryStripper(std::forward(ts)...); }