mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
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:
parent
292017d7bd
commit
e4fddc75f8
Notes:
sideshowbarker
2024-07-18 04:46:35 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/e4fddc75f8 Pull-request: https://github.com/SerenityOS/serenity/pull/21268
1 changed files with 15 additions and 15 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue