mirror of https://github.com/helix-editor/helix
refactor: increase readability
split logic into variables and add commentspull/12043/head
parent
d4e4049ab7
commit
ef2b035e01
|
@ -63,15 +63,23 @@ pub fn separator_case_conversion(
|
||||||
let mut prev: Option<char> = None;
|
let mut prev: Option<char> = None;
|
||||||
|
|
||||||
for c in text.skip_while(|ch| ch.is_whitespace()) {
|
for c in text.skip_while(|ch| ch.is_whitespace()) {
|
||||||
if c.is_alphanumeric() {
|
if !c.is_alphanumeric() {
|
||||||
if prev.is_some_and(|p| p.is_lowercase()) && c.is_uppercase()
|
prev = Some(c);
|
||||||
|| !prev.is_some_and(|p| p.is_alphanumeric()) && !buf.is_empty()
|
continue;
|
||||||
{
|
|
||||||
buf.push(separator);
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.push(c.to_ascii_lowercase());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "camelCase" => transition at 'l' -> 'C'
|
||||||
|
let has_camel_transition = prev.is_some_and(|p| p.is_lowercase()) && c.is_uppercase();
|
||||||
|
// "email@somewhere" => transition at 'l' -> '@'
|
||||||
|
// first character must not be separator, e.g. @emailSomewhere should not become -email-somewhere
|
||||||
|
let has_alphanum_transition = !prev.is_some_and(|p| p.is_alphanumeric()) && !buf.is_empty();
|
||||||
|
|
||||||
|
if has_camel_transition || has_alphanum_transition {
|
||||||
|
buf.push(separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf.push(c.to_ascii_lowercase());
|
||||||
|
|
||||||
prev = Some(c);
|
prev = Some(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue