aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-12-25 17:05:42 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-12-25 17:05:42 +0100
commit35507bfecf829fa1cc9166d0f1cfe9249ffed92b (patch)
treec029bad30ae3b6fa4aed19f5a4dcf1024fa77745
parent8b43e105beebbefcd1597cb51a28c78360d78197 (diff)
downloadprimstav-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.
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs14
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,9 +1,4 @@
[[package]]
-name = "Inflector"
-version = "0.11.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
-[[package]]
name = "chrono"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -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 <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())) {