yake-rust 1.0.3

Yake (Yet Another Keyword Extractor) in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
pub trait PluralHelper {
    /// Omit the last `s` symbol in a string.
    ///
    /// How to use: `some_string.to_lowercase().to_single()`
    fn to_single(self) -> Self;
}

impl<'a> PluralHelper for &'a str {
    fn to_single(self) -> &'a str {
        if self.chars().take(4).count() > 3 && (self.ends_with(['s', 'S'])) {
            &self[0..self.len() - 1]
        } else {
            self
        }
    }
}