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. --- Cargo.lock | 7 ------- Cargo.toml | 1 - src/main.rs | 14 ++++++++++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 39308f9..de957ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,8 +1,3 @@ -[[package]] -name = "Inflector" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "chrono" version = "0.4.6" @@ -45,7 +40,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "primstav" version = "0.1.0" dependencies = [ - "Inflector 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde_yaml 0.8.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -109,7 +103,6 @@ dependencies = [ ] [metadata] -"checksum Inflector 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4467f98bb61f615f8273359bf1c989453dfc1ea4a45ae9298f1dcd0672febe5d" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum dtoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6d301140eb411af13d3115f9a562c85cc6b541ade9dfa314132244aaee7489dd" "checksum libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d2857ec59fadc0773853c664d2d18e7198e83883e7060b63c924cb077bd5c74" diff --git a/Cargo.toml b/Cargo.toml index bb9e372..81c7ed8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,4 @@ edition = "2018" [dependencies] chrono = "0.4.6" -Inflector = {version = "0.11.3", default-features=false } # We don't need pluralization etc serde_yaml = "0.8.8" 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