From 47826f53a4ef4dfc2f8d023861880b2f5e52dd6a Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:32:14 +0000 Subject: [PATCH] refactor: better function naming --- helix-core/src/case_conversion.rs | 54 ++++++++++++++-------------- helix-core/src/snippets/elaborate.rs | 14 ++++---- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/helix-core/src/case_conversion.rs b/helix-core/src/case_conversion.rs index 5b1f64cc8..d893d1009 100644 --- a/helix-core/src/case_conversion.rs +++ b/helix-core/src/case_conversion.rs @@ -2,7 +2,7 @@ use crate::Tendril; // todo: should this be grapheme aware? -pub fn to_simple_case_with( +pub fn simple_case_conversion( text: impl Iterator, buf: &mut Tendril, transform_char: impl Fn(&char) -> char, @@ -12,7 +12,7 @@ pub fn to_simple_case_with( } } -pub fn to_camel_or_pascal_or_title_case_with( +pub fn complex_case_conversion( text: impl Iterator, buf: &mut Tendril, capitalize_first: bool, @@ -49,7 +49,7 @@ pub fn to_camel_or_pascal_or_title_case_with( } } -pub fn to_case_with_separator( +pub fn separator_case_conversion( text: impl Iterator, buf: &mut Tendril, separator: char, @@ -70,8 +70,8 @@ pub fn to_case_with_separator( } } -pub fn to_alternate_case_with(text: impl Iterator, buf: &mut Tendril) { - to_simple_case_with(text, buf, |c| { +pub fn into_alternate_case(text: impl Iterator, buf: &mut Tendril) { + simple_case_conversion(text, buf, |c| { if c.is_uppercase() { c.to_ascii_lowercase() } else if c.is_lowercase() { @@ -82,32 +82,32 @@ pub fn to_alternate_case_with(text: impl Iterator, buf: &mut Tendri }); } -pub fn to_upper_case_with(text: impl Iterator, buf: &mut Tendril) { - to_simple_case_with(text, buf, char::to_ascii_uppercase); +pub fn into_upper_case(text: impl Iterator, buf: &mut Tendril) { + simple_case_conversion(text, buf, char::to_ascii_uppercase); } -pub fn to_lower_case_with(text: impl Iterator, buf: &mut Tendril) { - to_simple_case_with(text, buf, char::to_ascii_lowercase); +pub fn into_lower_case(text: impl Iterator, buf: &mut Tendril) { + simple_case_conversion(text, buf, char::to_ascii_lowercase); } -pub fn to_kebab_case_with(text: impl Iterator, buf: &mut Tendril) { - to_case_with_separator(text, buf, '-'); +pub fn into_kebab_case(text: impl Iterator, buf: &mut Tendril) { + separator_case_conversion(text, buf, '-'); } -pub fn to_snake_case_with(text: impl Iterator, buf: &mut Tendril) { - to_case_with_separator(text, buf, '_'); +pub fn into_snake_case(text: impl Iterator, buf: &mut Tendril) { + separator_case_conversion(text, buf, '_'); } -pub fn to_title_case_with(text: impl Iterator, buf: &mut Tendril) { - to_camel_or_pascal_or_title_case_with(text, buf, true, true, Some(' ')); +pub fn into_title_case(text: impl Iterator, buf: &mut Tendril) { + complex_case_conversion(text, buf, true, true, Some(' ')); } -pub fn to_camel_case_with(text: impl Iterator, buf: &mut Tendril) { - to_camel_or_pascal_or_title_case_with(text, buf, false, true, None); +pub fn into_camel_case(text: impl Iterator, buf: &mut Tendril) { + complex_case_conversion(text, buf, false, true, None); } -pub fn to_pascal_case_with(text: impl Iterator, buf: &mut Tendril) { - to_camel_or_pascal_or_title_case_with(text, buf, true, true, None); +pub fn into_pascal_case(text: impl Iterator, buf: &mut Tendril) { + complex_case_conversion(text, buf, true, true, None); } fn to_case(text: I, to_case_with: fn(I, &mut Tendril)) -> Tendril @@ -120,35 +120,35 @@ where } pub fn to_camel_case(text: impl Iterator) -> Tendril { - to_case(text, to_camel_case_with) + to_case(text, into_camel_case) } pub fn to_lower_case(text: impl Iterator) -> Tendril { - to_case(text, to_lower_case_with) + to_case(text, into_lower_case) } pub fn to_upper_case(text: impl Iterator) -> Tendril { - to_case(text, to_upper_case_with) + to_case(text, into_upper_case) } pub fn to_pascal_case(text: impl Iterator) -> Tendril { - to_case(text, to_pascal_case_with) + to_case(text, into_pascal_case) } pub fn to_alternate_case(text: impl Iterator) -> Tendril { - to_case(text, to_alternate_case_with) + to_case(text, into_alternate_case) } pub fn to_title_case(text: impl Iterator) -> Tendril { - to_case(text, to_title_case_with) + to_case(text, into_title_case) } pub fn to_kebab_case(text: impl Iterator) -> Tendril { - to_case(text, to_kebab_case_with) + to_case(text, into_kebab_case) } pub fn to_snake_case(text: impl Iterator) -> Tendril { - to_case(text, to_snake_case_with) + to_case(text, into_snake_case) } #[cfg(test)] diff --git a/helix-core/src/snippets/elaborate.rs b/helix-core/src/snippets/elaborate.rs index 012d1db77..0ae5e4adf 100644 --- a/helix-core/src/snippets/elaborate.rs +++ b/helix-core/src/snippets/elaborate.rs @@ -10,9 +10,9 @@ use regex_cursor::engines::meta::Regex; use regex_cursor::regex_automata::util::syntax::Config as RegexConfig; use ropey::RopeSlice; -use crate::case_conversion::to_lower_case_with; -use crate::case_conversion::to_upper_case_with; -use crate::case_conversion::{to_camel_case_with, to_pascal_case_with}; +use crate::case_conversion::into_lower_case; +use crate::case_conversion::into_upper_case; +use crate::case_conversion::{into_camel_case, into_pascal_case}; use crate::snippets::parser::{self, CaseChange, FormatItem}; use crate::snippets::{TabstopIdx, LAST_TABSTOP_IDX}; use crate::Tendril; @@ -348,15 +348,15 @@ impl Transform { if let Some(cap) = cap.get_group(i).filter(|i| !i.is_empty()) { let mut chars = doc.byte_slice(cap.range()).chars(); match change { - CaseChange::Upcase => to_upper_case_with(chars, &mut buf), - CaseChange::Downcase => to_lower_case_with(chars, &mut buf), + CaseChange::Upcase => into_upper_case(chars, &mut buf), + CaseChange::Downcase => into_lower_case(chars, &mut buf), CaseChange::Capitalize => { let first_char = chars.next().unwrap(); buf.extend(first_char.to_uppercase()); buf.extend(chars); } - CaseChange::PascalCase => to_pascal_case_with(chars, &mut buf), - CaseChange::CamelCase => to_camel_case_with(chars, &mut buf), + CaseChange::PascalCase => into_pascal_case(chars, &mut buf), + CaseChange::CamelCase => into_camel_case(chars, &mut buf), } } }