From 35507bfecf829fa1cc9166d0f1cfe9249ffed92b Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 25 Dec 2018 17:05:42 +0100 Subject: Replace Inflector crate with homebrewed capitalize function. The Inflector crate did funky things with whitespace and punctuation, which is not desireable to us. --- src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/main.rs') 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 . 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::() + &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::>(); 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())) { -- cgit v1.2.3