Skip to content

Commit

Permalink
implement plural helper as the plurify library
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Dec 18, 2024
1 parent 18b380f commit f5eb9a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
12 changes: 1 addition & 11 deletions src/app/browser/window/tab/item/page/search/form/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)]
}]
}

0 comments on commit f5eb9a1

Please sign in to comment.