accept the pointer by & in consume_hilites, rather than by a pointer to the pointer

This commit is contained in:
natasha 2023-04-04 14:39:03 +01:00
parent 2e9607f9c1
commit f3560a295d
3 changed files with 8 additions and 8 deletions

View File

@ -3,7 +3,7 @@
namespace HiliteComparator
{
[[maybe_unused]] Hilite consume_hilites(const char ** ptr_ptr)
[[maybe_unused]] Hilite consume_hilites(const char * & ptr)
{
const char * last_hilite = nullptr;
while (true)
@ -11,9 +11,9 @@ namespace HiliteComparator
bool changed_hilite = false;
for (Hilite hilite : HILITES)
{
if (std::string_view(*ptr_ptr).starts_with(hilite))
if (std::string_view(ptr).starts_with(hilite))
{
*ptr_ptr += strlen(hilite);
ptr += strlen(hilite);
changed_hilite = true;
last_hilite = hilite;
}
@ -35,7 +35,7 @@ String remove_hilites(std::string_view string)
String string_without_hilites;
while (true)
{
consume_hilites(&ptr);
consume_hilites(ptr);
if (ptr == string.end())
return string_without_hilites;
string_without_hilites += *(ptr++);
@ -64,11 +64,11 @@ bool are_equal_with_hilites(std::string_view left, std::string_view right)
// Consume all prefix hilites, update the current hilite to be the last one.
Hilite last_hilite;
last_hilite = consume_hilites(&left_it);
last_hilite = consume_hilites(left_it);
if (last_hilite != nullptr)
left_hilite = last_hilite;
last_hilite = consume_hilites(&right_it);
last_hilite = consume_hilites(right_it);
if (last_hilite != nullptr)
right_hilite = last_hilite;

View File

@ -18,7 +18,7 @@ const std::vector<Hilite> HILITES = {
DB::IAST::hilite_none
};
[[maybe_unused]] Hilite consume_hilites(const char ** ptr_ptr);
[[maybe_unused]] Hilite consume_hilites(const char * & ptr);
String remove_hilites(std::string_view string);

View File

@ -20,7 +20,7 @@ TEST(HiliteComparator, ConsumeHilites)
s += IAST::hilite_keyword;
const char * ptr = s.c_str();
const char * expected_ptr = strchr(ptr, 't');
const char * last_hilite = consume_hilites(&ptr);
const char * last_hilite = consume_hilites(ptr);
ASSERT_EQ(expected_ptr, ptr);
ASSERT_TRUE(last_hilite != nullptr);
ASSERT_EQ(IAST::hilite_function, last_hilite);