mirror of https://github.com/helix-editor/helix
feat: better implementation of title_case
parent
355b2ba290
commit
f1cf46f022
|
@ -125,8 +125,8 @@ pub fn to_kebab_case_with(text: impl Iterator<Item = char>, buf: &mut Tendril) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_title_case_with(text: impl Iterator<Item = char>, buf: &mut Tendril) {
|
pub fn to_title_case_with(text: impl Iterator<Item = char>, buf: &mut Tendril) {
|
||||||
let mut at_word_start = false;
|
let mut at_word_start = true;
|
||||||
for c in text {
|
for (i, c) in text.enumerate() {
|
||||||
// we don't count _ as a word char here so case conversions work well
|
// we don't count _ as a word char here so case conversions work well
|
||||||
if !c.is_alphanumeric() {
|
if !c.is_alphanumeric() {
|
||||||
at_word_start = true;
|
at_word_start = true;
|
||||||
|
@ -134,7 +134,9 @@ pub fn to_title_case_with(text: impl Iterator<Item = char>, buf: &mut Tendril) {
|
||||||
}
|
}
|
||||||
if at_word_start {
|
if at_word_start {
|
||||||
at_word_start = false;
|
at_word_start = false;
|
||||||
|
if i != 0 {
|
||||||
buf.push(' ');
|
buf.push(' ');
|
||||||
|
}
|
||||||
buf.extend(c.to_uppercase());
|
buf.extend(c.to_uppercase());
|
||||||
} else {
|
} else {
|
||||||
buf.push(c)
|
buf.push(c)
|
||||||
|
|
Loading…
Reference in New Issue