From e4fddc75f88aaca02b21254a208e3258a26dfe3f Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Fri, 29 Sep 2023 17:36:19 +0100 Subject: [PATCH] AK/FuzzyMatch: Check every match for neighbor character bonuses Previously, the first match index was not checked to see if the camel case or separator bonuses applied. The camel case bonus could also be incorrectly applied where strings had non-alphabetical characters. --- AK/FuzzyMatch.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/AK/FuzzyMatch.cpp b/AK/FuzzyMatch.cpp index 7033c458df..fc090c7248 100644 --- a/AK/FuzzyMatch.cpp +++ b/AK/FuzzyMatch.cpp @@ -37,24 +37,24 @@ static int calculate_score(StringView string, u8* index_points, size_t index_poi for (size_t i = 0; i < index_points_size; i++) { u8 current_idx = index_points[i]; - if (current_idx == 0) + if (i > 0) { + u8 previous_idx = index_points[i - 1]; + if (current_idx - 1 == previous_idx) + out_score += SEQUENTIAL_BONUS; + } + + if (current_idx == 0) { out_score += FIRST_LETTER_BONUS; + } else { + u32 current_character = string[current_idx]; + u32 neighbor_character = string[current_idx - 1]; - if (i == 0) - continue; + if (is_ascii_lower_alpha(neighbor_character) && is_ascii_upper_alpha(current_character)) + out_score += CAMEL_BONUS; - u8 previous_idx = index_points[i - 1]; - if (current_idx - 1 == previous_idx) - out_score += SEQUENTIAL_BONUS; - - u32 current_character = string[current_idx]; - u32 neighbor_character = string[current_idx - 1]; - - if (neighbor_character != to_ascii_uppercase(neighbor_character) && current_character != to_ascii_lowercase(current_character)) - out_score += CAMEL_BONUS; - - if (neighbor_character == '_' || neighbor_character == ' ') - out_score += SEPARATOR_BONUS; + if (neighbor_character == '_' || neighbor_character == ' ') + out_score += SEPARATOR_BONUS; + } } return out_score;