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.
This commit is contained in:
Tim Ledbetter 2023-09-29 17:36:19 +01:00 committed by Andreas Kling
parent 292017d7bd
commit e4fddc75f8
Notes: sideshowbarker 2024-07-18 04:46:35 +09:00

View File

@ -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;