From f13c0ba5a788d6c14194e88834781abea645a397 Mon Sep 17 00:00:00 2001 From: Hanif Bin Ariffin Date: Mon, 19 Jul 2021 21:32:52 +0800 Subject: [PATCH] Remove new from struct names Signed-off-by: Hanif Bin Ariffin --- src/uu/tr/src/operation.rs | 44 +++++++++++++++++++------------------- src/uu/tr/src/tr.rs | 18 ++++++++-------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/uu/tr/src/operation.rs b/src/uu/tr/src/operation.rs index 30e7b6af5..ecc3d52a3 100644 --- a/src/uu/tr/src/operation.rs +++ b/src/uu/tr/src/operation.rs @@ -268,26 +268,26 @@ impl Sequence { } } -pub trait SymbolTranslatorNew { +pub trait SymbolTranslator { fn translate(&mut self, current: char) -> Option; } #[derive(Debug, Clone)] -pub struct DeleteOperationNew { +pub struct DeleteOperation { set: Vec, complement_flag: bool, } -impl DeleteOperationNew { - pub fn new(set: Vec, complement_flag: bool) -> DeleteOperationNew { - DeleteOperationNew { +impl DeleteOperation { + pub fn new(set: Vec, complement_flag: bool) -> DeleteOperation { + DeleteOperation { set, complement_flag, } } } -impl SymbolTranslatorNew for DeleteOperationNew { +impl SymbolTranslator for DeleteOperation { fn translate(&mut self, current: char) -> Option { let found = self.set.iter().any(|sequence| match sequence { Sequence::Char(c) => c.eq(¤t), @@ -298,7 +298,7 @@ impl SymbolTranslatorNew for DeleteOperationNew { } #[derive(Debug, Clone)] -pub enum TranslateOperationNew { +pub enum TranslateOperation { Standard(HashMap), Complement( // iter @@ -314,7 +314,7 @@ pub enum TranslateOperationNew { ), } -impl TranslateOperationNew { +impl TranslateOperation { fn next_complement_char(mut iter: u32) -> (u32, char) { while char::from_u32(iter).is_none() { iter = iter.saturating_add(1) @@ -323,13 +323,13 @@ impl TranslateOperationNew { } } -impl TranslateOperationNew { +impl TranslateOperation { pub fn new( pset1: Vec, pset2: Vec, truncate_set1: bool, complement: bool, - ) -> TranslateOperationNew { + ) -> TranslateOperation { let mut set1 = pset1 .into_iter() .flat_map(Sequence::dissolve) @@ -343,7 +343,7 @@ impl TranslateOperationNew { } let fallback = set2.last().cloned().unwrap(); if complement { - TranslateOperationNew::Complement( + TranslateOperation::Complement( 0, set1, set2, @@ -352,7 +352,7 @@ impl TranslateOperationNew { HashMap::new(), ) } else { - TranslateOperationNew::Standard( + TranslateOperation::Standard( set1.into_iter() .zip(set2.into_iter().chain(std::iter::repeat(fallback))) .collect::>(), @@ -361,15 +361,15 @@ impl TranslateOperationNew { } } -impl SymbolTranslatorNew for TranslateOperationNew { +impl SymbolTranslator for TranslateOperation { fn translate(&mut self, current: char) -> Option { match self { - TranslateOperationNew::Standard(map) => Some( + TranslateOperation::Standard(map) => Some( map.iter() .find_map(|(l, r)| l.eq(¤t).then(|| *r)) .unwrap_or(current), ), - TranslateOperationNew::Complement(iter, set1, set2, fallback, mapped_characters) => { + TranslateOperation::Complement(iter, set1, set2, fallback, mapped_characters) => { // First, try to see if current char is already mapped // If so, return the mapped char // Else, pop from set2 @@ -381,7 +381,7 @@ impl SymbolTranslatorNew for TranslateOperationNew { while mapped_characters.get(¤t).is_none() { if let Some(p) = set2.pop() { let (next_index, next_value) = - TranslateOperationNew::next_complement_char(*iter); + TranslateOperation::next_complement_char(*iter); *iter = next_index; mapped_characters.insert(next_value, p); } else { @@ -396,15 +396,15 @@ impl SymbolTranslatorNew for TranslateOperationNew { } #[derive(Debug, Clone)] -pub struct SqueezeOperationNew { +pub struct SqueezeOperation { squeeze_set: Vec, complement: bool, previous: Option, } -impl SqueezeOperationNew { - pub fn new(squeeze_set: Vec, complement: bool) -> SqueezeOperationNew { - SqueezeOperationNew { +impl SqueezeOperation { + pub fn new(squeeze_set: Vec, complement: bool) -> SqueezeOperation { + SqueezeOperation { squeeze_set: squeeze_set .into_iter() .flat_map(Sequence::dissolve) @@ -415,7 +415,7 @@ impl SqueezeOperationNew { } } -impl SymbolTranslatorNew for SqueezeOperationNew { +impl SymbolTranslator for SqueezeOperation { fn translate(&mut self, current: char) -> Option { if self.complement { let next = if self.squeeze_set.iter().any(|c| c.eq(¤t)) { @@ -461,7 +461,7 @@ impl SymbolTranslatorNew for SqueezeOperationNew { pub fn translate_input_new(input: &mut R, output: &mut W, mut translator: T) where - T: SymbolTranslatorNew, + T: SymbolTranslator, R: BufRead, W: Write, { diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index c21bc679e..77fc35bbc 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -18,10 +18,10 @@ mod operation; use clap::{crate_version, App, Arg}; use nom::AsBytes; -use operation::{translate_input_new, Sequence, SqueezeOperationNew, TranslateOperationNew}; +use operation::{translate_input_new, Sequence, SqueezeOperation, TranslateOperation}; use std::io::{stdin, stdout, BufReader, BufWriter}; -use crate::operation::DeleteOperationNew; +use crate::operation::DeleteOperation; use uucore::InvalidEncodingHandling; static ABOUT: &str = "translate or delete characters"; @@ -96,30 +96,30 @@ pub fn uumain(args: impl uucore::Args) -> i32 { { let mut delete_writer = BufWriter::new(&mut delete_buffer); let delete_op = - DeleteOperationNew::new(Sequence::parse_set_string(&sets[0]), complement_flag); + DeleteOperation::new(Sequence::parse_set_string(&sets[0]), complement_flag); translate_input_new(&mut locked_stdin, &mut delete_writer, delete_op); } { let mut squeeze_reader = BufReader::new(delete_buffer.as_bytes()); let squeeze_op = - SqueezeOperationNew::new(Sequence::parse_set_string(&sets[1]), complement_flag); + SqueezeOperation::new(Sequence::parse_set_string(&sets[1]), complement_flag); translate_input_new(&mut squeeze_reader, &mut buffered_stdout, squeeze_op); } } else { - let op = DeleteOperationNew::new(Sequence::parse_set_string(&sets[0]), complement_flag); + let op = DeleteOperation::new(Sequence::parse_set_string(&sets[0]), complement_flag); translate_input_new(&mut locked_stdin, &mut buffered_stdout, op); } } else if squeeze_flag { if sets.len() < 2 { let op = - SqueezeOperationNew::new(Sequence::parse_set_string(&sets[0]), complement_flag); + SqueezeOperation::new(Sequence::parse_set_string(&sets[0]), complement_flag); translate_input_new(&mut locked_stdin, &mut buffered_stdout, op); } else { let mut translate_buffer = vec![]; { let mut writer = BufWriter::new(&mut translate_buffer); - let translate_op = TranslateOperationNew::new( + let translate_op = TranslateOperation::new( Sequence::parse_set_string(&sets[0]), Sequence::parse_set_string(&sets[1]), truncate_set1_flag, @@ -130,12 +130,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 { { let mut reader = BufReader::new(translate_buffer.as_bytes()); let squeeze_op = - SqueezeOperationNew::new(Sequence::parse_set_string(&sets[1]), false); + SqueezeOperation::new(Sequence::parse_set_string(&sets[1]), false); translate_input_new(&mut reader, &mut buffered_stdout, squeeze_op); } } } else { - let op = TranslateOperationNew::new( + let op = TranslateOperation::new( Sequence::parse_set_string(&sets[0]), Sequence::parse_set_string(&sets[1]), truncate_set1_flag,