History

refactor

Sebastian Thiel committed 3 years ago

Commit dc6b5be1 parent 3749b881 file · +11 −4Browse files

Unified · Split

cargo-smart-release/src/changelog/write.rs+11−4
@@ -1,4 +1,5 @@
11 use gix::{bstr::ByteSlice, url::Scheme, Url};
2+use std::borrow::Cow;
23
34 use crate::{
45 changelog,
@@ -397,8 +398,14 @@ fn format_oid(id: &gix::oid, link_mode: &Linkables) -> String { · 392 unmodified lines
397398 }
398399 }
399400
400−fn capitalize_message_title(title: &String) -> String {
401− let mut v: Vec<char> = title.chars().collect();
402− v[0] = v[0].to_uppercase().nth(0).unwrap();
403− v.into_iter().collect()
401+fn capitalize_message_title<'a>(title: impl Into<Cow<'a, str>>) -> Cow<'a, str> {
402+ let mut title = title.into();
403+ let mut chars = title.chars();
404+ if let Some(first) = chars
405+ .next()
406+ .and_then(|c| (c.to_uppercase().next() != Some(c)).then_some(c))
407+ {
408+ *title.to_mut() = first.to_uppercase().chain(chars).collect();
409+ }
410+ title
404411 }