initiative_core/utils/
mod.rs1#[cfg(any(test, feature = "integration-tests"))]
2pub mod test_utils;
3
4pub use case_insensitive_str::CaseInsensitiveStr;
5pub use quoted_word_iter::{quoted_phrases, quoted_words};
6pub use substr::Substr;
7
8mod case_insensitive_str;
9mod quoted_word_iter;
10mod substr;
11
12pub fn capitalize(input: &str) -> String {
13 let mut result = String::with_capacity(input.len());
14 let mut char_iter = input.chars();
15
16 if let Some(c) = char_iter.next() {
17 c.to_uppercase().for_each(|c| result.push(c));
18 }
19 char_iter.for_each(|c| result.push(c));
20
21 result
22}
23
24pub fn pluralize(word: &str) -> (&str, &str) {
25 match word {
26 "Goose" => ("Geese", ""),
27 "Beef" | "Carp" | "Cod" | "Deer" | "Perch" | "Potatoes" | "Sheep" | "Squid" => (word, ""),
28 s if s.ends_with('f') => (&word[..(word.len() - 1)], "ves"),
29 s if s.ends_with("ey") => (&word[..(word.len() - 2)], "ies"),
30 s if s.ends_with('y') => (&word[..(word.len() - 1)], "ies"),
31 s if s.ends_with(&['s', 'x', 'z'][..]) => (word, "es"),
32 s if s.ends_with("ch") => (word, "es"),
33 s if s.ends_with("sh") => (word, "es"),
34 s if s.ends_with(&['s', 'x'][..]) => (word, "es"),
35 _ => (word, "s"),
36 }
37}