From 6a931c8effeaec7fbabbf08d980a42a93ee58ea0 Mon Sep 17 00:00:00 2001 From: Yerlan Sergaziyev Date: Sun, 8 Oct 2023 21:28:15 +0200 Subject: [PATCH] naming and formatting --- converter/src/convert.rs | 14 ++++++++++---- converter/src/utils.rs | 4 ++-- converter/src/utils/parseargs.rs | 10 +++++----- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/converter/src/convert.rs b/converter/src/convert.rs index 913e92f..0df23bc 100644 --- a/converter/src/convert.rs +++ b/converter/src/convert.rs @@ -20,17 +20,18 @@ impl CharConverter { } fn convert_char(&mut self, c: &str) -> String { - let hard_char = Self::HARDS.contains(c); - let soft_char = Self::SOFTS.contains(c); + let is_hard = Self::HARDS.contains(c); + let is_soft = Self::SOFTS.contains(c); let current: String; + match self.table.get(c) { Some(c) => { if self.might_need_prefix { - if hard_char || self.accumulator.len() > 3 { + if is_hard || self.accumulator.len() > 3 { current = format!("{}{}", self.accumulator, c); self.might_need_prefix = false; self.accumulator = String::with_capacity(13); - } else if soft_char { + } else if is_soft { current = format!("'{}{}", self.accumulator, c); self.might_need_prefix = false; self.accumulator = String::with_capacity(13); @@ -49,6 +50,7 @@ impl CharConverter { self.accumulator = String::with_capacity(13); } }; + current } } @@ -56,10 +58,12 @@ impl CharConverter { pub fn convert_line(input_string: &str) -> String { let mut converter = CharConverter::new(); let cyrillic = format!("{input_string}_"); + let latin = UnicodeSegmentation::graphemes(cyrillic.as_str(), true) .map(|c| c.to_owned()) .map(|c| converter.convert_char(&c.to_owned())) .collect::(); + String::from(latin.strip_suffix('_').unwrap()) .replace("'E", "E") .replace("'e", "e") @@ -114,10 +118,12 @@ fn get_table() -> HashMap { (String::from("Ю"), String::from("Yu")), (String::from("Я"), String::from("Ya")), ]); + let lows = caps .iter() .map(|i| (i.0.to_lowercase(), i.1.to_lowercase())) .collect::>(); + caps.extend(lows); caps } diff --git a/converter/src/utils.rs b/converter/src/utils.rs index 64cdce1..6367b0d 100644 --- a/converter/src/utils.rs +++ b/converter/src/utils.rs @@ -3,7 +3,7 @@ use std::path::Path; pub mod parseargs; pub struct Utils { - arguments: parseargs::Arguments, + arguments: parseargs::CliArgs, } impl Utils { @@ -47,7 +47,7 @@ impl Utils { } fn check_output_file(&self, input_filename: &str) -> String { - let parseargs::Arguments { + let parseargs::CliArgs { prefix, suffix, force, diff --git a/converter/src/utils/parseargs.rs b/converter/src/utils/parseargs.rs index ce9dc80..797aba7 100644 --- a/converter/src/utils/parseargs.rs +++ b/converter/src/utils/parseargs.rs @@ -2,11 +2,11 @@ use clap::Parser; #[derive(Parser, Debug)] #[command(author, version, about, long_about=None)] -pub struct Arguments { - #[arg(short = 'p', long, default_value_t = String::from("lat-"))] +pub struct CliArgs { + #[arg(short, long, default_value_t = String::from("lat-"))] pub prefix: String, - #[arg(short = 's', long, default_value_t = String::new())] + #[arg(short, long, default_value_t = String::new())] pub suffix: String, #[arg(short, long)] @@ -15,7 +15,7 @@ pub struct Arguments { pub input_filenames: Vec, } -pub fn parse() -> Arguments { - Arguments::parse() +pub fn parse() -> CliArgs { + CliArgs::parse() }