Skip to content

Commit

Permalink
naming and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
yerlaser committed Oct 8, 2023
1 parent 8d85fd9 commit 6a931c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
14 changes: 10 additions & 4 deletions converter/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -49,17 +50,20 @@ impl CharConverter {
self.accumulator = String::with_capacity(13);
}
};

current
}
}

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>();

String::from(latin.strip_suffix('_').unwrap())
.replace("'E", "E")
.replace("'e", "e")
Expand Down Expand Up @@ -114,10 +118,12 @@ fn get_table() -> HashMap<String, String> {
(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::<HashMap<String, String>>();

caps.extend(lows);
caps
}
4 changes: 2 additions & 2 deletions converter/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;
pub mod parseargs;

pub struct Utils {
arguments: parseargs::Arguments,
arguments: parseargs::CliArgs,
}

impl Utils {
Expand Down Expand Up @@ -47,7 +47,7 @@ impl Utils {
}

fn check_output_file(&self, input_filename: &str) -> String {
let parseargs::Arguments {
let parseargs::CliArgs {
prefix,
suffix,
force,
Expand Down
10 changes: 5 additions & 5 deletions converter/src/utils/parseargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -15,7 +15,7 @@ pub struct Arguments {
pub input_filenames: Vec<String>,
}

pub fn parse() -> Arguments {
Arguments::parse()
pub fn parse() -> CliArgs {
CliArgs::parse()
}

0 comments on commit 6a931c8

Please sign in to comment.