diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-12-25 17:05:42 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-12-25 17:05:42 +0100 |
commit | 35507bfecf829fa1cc9166d0f1cfe9249ffed92b (patch) | |
tree | c029bad30ae3b6fa4aed19f5a4dcf1024fa77745 /src | |
parent | 8b43e105beebbefcd1597cb51a28c78360d78197 (diff) | |
download | primstav-35507bfecf829fa1cc9166d0f1cfe9249ffed92b.tar.gz primstav-35507bfecf829fa1cc9166d0f1cfe9249ffed92b.tar.bz2 primstav-35507bfecf829fa1cc9166d0f1cfe9249ffed92b.zip |
Replace Inflector crate with homebrewed capitalize function.
The Inflector crate did funky things with whitespace and punctuation,
which is not desireable to us.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index c4996f5..8f5f038 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,6 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use chrono; -use inflector::Inflector; use serde_yaml; use std::io::BufReader; use std::iter::Iterator; @@ -23,13 +22,20 @@ use std::fs::File; use std::str::FromStr; use std::string::ToString; +fn capitalize(s: &str) -> String { + match s.chars().next() { + Some(ch) => ch.to_uppercase().collect::<String>() + &s[1..], + None => String::new(), + } +} + fn print_entry(d: &serde_yaml::Value) { let name = d.get("name").unwrap(); - println!("{}", name.as_str().unwrap().to_sentence_case()); + println!("{}", capitalize(name.as_str().unwrap())); if let Some(alt_names) = d.get("alternative_names") { let names = alt_names.as_sequence().unwrap().iter() - .map(|v| v.as_str().unwrap().to_title_case()) + .map(|v| capitalize(v.as_str().unwrap())) .collect::<Vec<_>>(); println!("({})", names.join(", ")); } @@ -52,7 +58,7 @@ fn main() { None => chrono::Local::today().naive_utc(), }; - println!("{}", local_date.format("%A %d. %b, %Y")); + println!("{}", capitalize(&local_date.format("%A %d. %b, %Y").to_string())); let key = local_date.format("%d%m").to_string(); match data.get(serde_yaml::Value::Number(u32::from_str(&key).unwrap().into())) { |