Use for loop in capitalize implementation (#1377)

This commit is contained in:
Casey Rodarmor 2022-10-24 20:52:43 -07:00 committed by GitHub
parent aaef61b908
commit deac684aaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -81,18 +81,15 @@ fn arch(_context: &FunctionContext) -> Result<String, String> {
}
fn capitalize(_context: &FunctionContext, s: &str) -> Result<String, String> {
Ok(
s.chars()
.enumerate()
.flat_map(|(i, c)| {
if i == 0 {
c.to_uppercase().collect::<Vec<_>>()
} else {
c.to_lowercase().collect::<Vec<_>>()
}
})
.collect(),
)
let mut capitalized = String::new();
for (i, c) in s.chars().enumerate() {
if i == 0 {
capitalized.extend(c.to_uppercase());
} else {
capitalized.extend(c.to_lowercase());
}
}
Ok(capitalized)
}
fn clean(_context: &FunctionContext, path: &str) -> Result<String, String> {