implement plural helper as the plurify library

This commit is contained in:
yggverse 2024-12-18 12:54:13 +02:00
parent 18b380f5ec
commit f5eb9a1280
2 changed files with 4 additions and 11 deletions

View File

@ -45,6 +45,9 @@ version = "0.9.1"
package = "sourceview5"
version = "0.9.1"
[dependencies.plurify]
version = "0.1.0"
# development
[patch.crates-io]
# ggemini = { git = "https://github.com/YGGverse/ggemini.git" }

View File

@ -24,7 +24,7 @@ impl Result {
pub fn update(&self, current: Option<usize>, total: usize) {
if total > 0 {
let matches = plural(total, &["match", "matches", "matches"]);
let matches = plurify::ns(total, &["match", "matches", "matches"]);
match current {
Some(position) => self
.label
@ -38,13 +38,3 @@ impl Result {
}
}
}
// Tools
fn plural<'a>(n: usize, s: &[&'a str]) -> &'a str {
s[if (n % 100) > 4 && (n % 100) < 20 {
2
} else {
[2, 0, 1, 1, 1, 2][std::cmp::min(n % 10, 5)]
}]
}