From 86edd4809658c0fd057760c2e935df8849a7da0c Mon Sep 17 00:00:00 2001 From: natasha Date: Tue, 4 Apr 2023 14:29:02 +0100 Subject: [PATCH] HiliteComparator: add Hilite alias for const char * representing hilites --- src/Parsers/HiliteComparator/HiliteComparator.cpp | 12 +++++++----- src/Parsers/HiliteComparator/HiliteComparator.h | 6 ++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Parsers/HiliteComparator/HiliteComparator.cpp b/src/Parsers/HiliteComparator/HiliteComparator.cpp index 03e60b4bc53..43abb3e4441 100644 --- a/src/Parsers/HiliteComparator/HiliteComparator.cpp +++ b/src/Parsers/HiliteComparator/HiliteComparator.cpp @@ -2,13 +2,13 @@ namespace HiliteComparator { -[[maybe_unused]] const char * consume_hilites(const char ** ptr_ptr) +[[maybe_unused]] Hilite consume_hilites(const char ** ptr_ptr) { const char * last_hilite = nullptr; while (true) { bool changed_hilite = false; - for (const char * hilite : HILITES) + for (Hilite hilite : HILITES) { if (std::string_view(*ptr_ptr).starts_with(hilite)) { @@ -55,13 +55,15 @@ bool are_equal_with_hilites(std::string_view left, std::string_view right) const char * left_it = left.begin(); const char * right_it = right.begin(); - const char * left_hilite = DB::IAST::hilite_none; - const char * right_hilite = DB::IAST::hilite_none; + Hilite left_hilite = DB::IAST::hilite_none; + Hilite right_hilite = DB::IAST::hilite_none; while (true) { // Consume all prefix hilites, update the current hilite to be the last one. - const char * last_hilite = consume_hilites(&left_it); + Hilite last_hilite; + + last_hilite = consume_hilites(&left_it); if (last_hilite != nullptr) left_hilite = last_hilite; diff --git a/src/Parsers/HiliteComparator/HiliteComparator.h b/src/Parsers/HiliteComparator/HiliteComparator.h index 1ced56364dd..e9e2aa0fe0d 100644 --- a/src/Parsers/HiliteComparator/HiliteComparator.h +++ b/src/Parsers/HiliteComparator/HiliteComparator.h @@ -5,7 +5,9 @@ namespace HiliteComparator { -const std::vector HILITES = +using Hilite = const char *; + +const std::vector HILITES = { DB::IAST::hilite_keyword, DB::IAST::hilite_identifier, @@ -16,7 +18,7 @@ const std::vector HILITES = DB::IAST::hilite_none }; -[[maybe_unused]] const char * consume_hilites(const char ** ptr_ptr); +[[maybe_unused]] Hilite consume_hilites(const char ** ptr_ptr); String remove_hilites(std::string_view string);