From fdd1a1c78f43720ffe4ed613cc3d17ef6bf0d7f6 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Sat, 11 Jan 2025 19:56:18 +0000 Subject: [PATCH] refactor: remove 1 layer of nesting --- helix-core/src/case_conversion.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/helix-core/src/case_conversion.rs b/helix-core/src/case_conversion.rs index ccc9c6465..0bd0053cc 100644 --- a/helix-core/src/case_conversion.rs +++ b/helix-core/src/case_conversion.rs @@ -35,21 +35,25 @@ pub fn smart_case_conversion( }; for current in chars.skip_while(|ch| ch.is_whitespace()) { - if current.is_alphanumeric() { - if has_camel_transition(prev, current) { - add_separator_if_needed(prev, buf); - should_capitalize_current = true; - } - if should_capitalize_current { - buf.push(current.to_ascii_uppercase()); - should_capitalize_current = false; - } else { - buf.push(current.to_ascii_lowercase()); - } - } else { + if !current.is_alphanumeric() { should_capitalize_current = true; add_separator_if_needed(prev, buf); + prev = Some(current); + continue; } + + if has_camel_transition(prev, current) { + add_separator_if_needed(prev, buf); + should_capitalize_current = true; + } + + if should_capitalize_current { + buf.push(current.to_ascii_uppercase()); + should_capitalize_current = false; + } else { + buf.push(current.to_ascii_lowercase()); + } + prev = Some(current); }