aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-12-25 23:57:11 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-12-26 00:02:49 +0100
commit1e1a65eaf06d5691001d1ec62aa4fb3d61b0d41c (patch)
tree812e4cb83c9f0610ed0db534e5621491d6ced1fb /src
parent3b01001a36199953f58b50948149e8c8e08c1908 (diff)
downloadprimstav-1e1a65eaf06d5691001d1ec62aa4fb3d61b0d41c.tar.gz
primstav-1e1a65eaf06d5691001d1ec62aa4fb3d61b0d41c.tar.bz2
primstav-1e1a65eaf06d5691001d1ec62aa4fb3d61b0d41c.zip
capitalize() would fail if first char were not ascii.
Enhanced version using chain iterator.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index a76b378..c33924d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,12 +25,21 @@ use std::string::ToString;
mod locale;
fn capitalize(s: &str) -> String {
- match s.chars().next() {
- Some(ch) => ch.to_uppercase().collect::<String>() + &s[1..],
+ let mut chars = s.chars();
+ match chars.next() {
+ Some(ch) => ch.to_uppercase().chain(chars).collect::<String>(),
None => String::new(),
}
}
+#[test]
+fn test_capitalize() {
+ assert_eq!("Flaccid", capitalize("flaccid"));
+ assert_eq!("Ångström", capitalize("ångström"));
+ assert_eq!("Å i lofoten", capitalize("å i lofoten"));
+ assert_eq!("Ååååh", capitalize("ååååh"));
+}
+
fn print_entry(d: &serde_yaml::Value) {
let name = d.get("name").unwrap();
println!("{}", capitalize(name.as_str().unwrap()));