mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:27:35 +00:00
Assistant: Simplify the logic of calculating bonus points
This does not change the results, but makes the code clearer.
This commit is contained in:
parent
ee17614e34
commit
e7eccf3de2
1 changed files with 17 additions and 17 deletions
|
@ -37,24 +37,24 @@ static int calculate_score(String const& string, u8* index_points, size_t index_
|
|||
for (size_t i = 0; i < index_points_size; i++) {
|
||||
u8 current_idx = index_points[i];
|
||||
|
||||
if (i > 0) {
|
||||
u8 previous_idx = index_points[i - 1];
|
||||
if (current_idx == previous_idx)
|
||||
out_score += SEQUENTIAL_BONUS;
|
||||
}
|
||||
|
||||
if (current_idx > 0) {
|
||||
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;
|
||||
} else {
|
||||
if (current_idx == 0)
|
||||
out_score += FIRST_LETTER_BONUS;
|
||||
}
|
||||
|
||||
if (i == 0)
|
||||
continue;
|
||||
|
||||
u8 previous_idx = index_points[i - 1];
|
||||
if (current_idx == 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;
|
||||
}
|
||||
|
||||
return out_score;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue