mirror of
https://github.com/uutils/coreutils
synced 2024-12-18 09:03:14 +00:00
Remove new from struct names
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
This commit is contained in:
parent
6ff826b712
commit
f13c0ba5a7
2 changed files with 31 additions and 31 deletions
|
@ -268,26 +268,26 @@ impl Sequence {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SymbolTranslatorNew {
|
pub trait SymbolTranslator {
|
||||||
fn translate(&mut self, current: char) -> Option<char>;
|
fn translate(&mut self, current: char) -> Option<char>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct DeleteOperationNew {
|
pub struct DeleteOperation {
|
||||||
set: Vec<Sequence>,
|
set: Vec<Sequence>,
|
||||||
complement_flag: bool,
|
complement_flag: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DeleteOperationNew {
|
impl DeleteOperation {
|
||||||
pub fn new(set: Vec<Sequence>, complement_flag: bool) -> DeleteOperationNew {
|
pub fn new(set: Vec<Sequence>, complement_flag: bool) -> DeleteOperation {
|
||||||
DeleteOperationNew {
|
DeleteOperation {
|
||||||
set,
|
set,
|
||||||
complement_flag,
|
complement_flag,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SymbolTranslatorNew for DeleteOperationNew {
|
impl SymbolTranslator for DeleteOperation {
|
||||||
fn translate(&mut self, current: char) -> Option<char> {
|
fn translate(&mut self, current: char) -> Option<char> {
|
||||||
let found = self.set.iter().any(|sequence| match sequence {
|
let found = self.set.iter().any(|sequence| match sequence {
|
||||||
Sequence::Char(c) => c.eq(¤t),
|
Sequence::Char(c) => c.eq(¤t),
|
||||||
|
@ -298,7 +298,7 @@ impl SymbolTranslatorNew for DeleteOperationNew {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum TranslateOperationNew {
|
pub enum TranslateOperation {
|
||||||
Standard(HashMap<char, char>),
|
Standard(HashMap<char, char>),
|
||||||
Complement(
|
Complement(
|
||||||
// iter
|
// iter
|
||||||
|
@ -314,7 +314,7 @@ pub enum TranslateOperationNew {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TranslateOperationNew {
|
impl TranslateOperation {
|
||||||
fn next_complement_char(mut iter: u32) -> (u32, char) {
|
fn next_complement_char(mut iter: u32) -> (u32, char) {
|
||||||
while char::from_u32(iter).is_none() {
|
while char::from_u32(iter).is_none() {
|
||||||
iter = iter.saturating_add(1)
|
iter = iter.saturating_add(1)
|
||||||
|
@ -323,13 +323,13 @@ impl TranslateOperationNew {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TranslateOperationNew {
|
impl TranslateOperation {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
pset1: Vec<Sequence>,
|
pset1: Vec<Sequence>,
|
||||||
pset2: Vec<Sequence>,
|
pset2: Vec<Sequence>,
|
||||||
truncate_set1: bool,
|
truncate_set1: bool,
|
||||||
complement: bool,
|
complement: bool,
|
||||||
) -> TranslateOperationNew {
|
) -> TranslateOperation {
|
||||||
let mut set1 = pset1
|
let mut set1 = pset1
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(Sequence::dissolve)
|
.flat_map(Sequence::dissolve)
|
||||||
|
@ -343,7 +343,7 @@ impl TranslateOperationNew {
|
||||||
}
|
}
|
||||||
let fallback = set2.last().cloned().unwrap();
|
let fallback = set2.last().cloned().unwrap();
|
||||||
if complement {
|
if complement {
|
||||||
TranslateOperationNew::Complement(
|
TranslateOperation::Complement(
|
||||||
0,
|
0,
|
||||||
set1,
|
set1,
|
||||||
set2,
|
set2,
|
||||||
|
@ -352,7 +352,7 @@ impl TranslateOperationNew {
|
||||||
HashMap::new(),
|
HashMap::new(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
TranslateOperationNew::Standard(
|
TranslateOperation::Standard(
|
||||||
set1.into_iter()
|
set1.into_iter()
|
||||||
.zip(set2.into_iter().chain(std::iter::repeat(fallback)))
|
.zip(set2.into_iter().chain(std::iter::repeat(fallback)))
|
||||||
.collect::<HashMap<_, _>>(),
|
.collect::<HashMap<_, _>>(),
|
||||||
|
@ -361,15 +361,15 @@ impl TranslateOperationNew {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SymbolTranslatorNew for TranslateOperationNew {
|
impl SymbolTranslator for TranslateOperation {
|
||||||
fn translate(&mut self, current: char) -> Option<char> {
|
fn translate(&mut self, current: char) -> Option<char> {
|
||||||
match self {
|
match self {
|
||||||
TranslateOperationNew::Standard(map) => Some(
|
TranslateOperation::Standard(map) => Some(
|
||||||
map.iter()
|
map.iter()
|
||||||
.find_map(|(l, r)| l.eq(¤t).then(|| *r))
|
.find_map(|(l, r)| l.eq(¤t).then(|| *r))
|
||||||
.unwrap_or(current),
|
.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
|
// First, try to see if current char is already mapped
|
||||||
// If so, return the mapped char
|
// If so, return the mapped char
|
||||||
// Else, pop from set2
|
// Else, pop from set2
|
||||||
|
@ -381,7 +381,7 @@ impl SymbolTranslatorNew for TranslateOperationNew {
|
||||||
while mapped_characters.get(¤t).is_none() {
|
while mapped_characters.get(¤t).is_none() {
|
||||||
if let Some(p) = set2.pop() {
|
if let Some(p) = set2.pop() {
|
||||||
let (next_index, next_value) =
|
let (next_index, next_value) =
|
||||||
TranslateOperationNew::next_complement_char(*iter);
|
TranslateOperation::next_complement_char(*iter);
|
||||||
*iter = next_index;
|
*iter = next_index;
|
||||||
mapped_characters.insert(next_value, p);
|
mapped_characters.insert(next_value, p);
|
||||||
} else {
|
} else {
|
||||||
|
@ -396,15 +396,15 @@ impl SymbolTranslatorNew for TranslateOperationNew {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SqueezeOperationNew {
|
pub struct SqueezeOperation {
|
||||||
squeeze_set: Vec<char>,
|
squeeze_set: Vec<char>,
|
||||||
complement: bool,
|
complement: bool,
|
||||||
previous: Option<char>,
|
previous: Option<char>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SqueezeOperationNew {
|
impl SqueezeOperation {
|
||||||
pub fn new(squeeze_set: Vec<Sequence>, complement: bool) -> SqueezeOperationNew {
|
pub fn new(squeeze_set: Vec<Sequence>, complement: bool) -> SqueezeOperation {
|
||||||
SqueezeOperationNew {
|
SqueezeOperation {
|
||||||
squeeze_set: squeeze_set
|
squeeze_set: squeeze_set
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(Sequence::dissolve)
|
.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<char> {
|
fn translate(&mut self, current: char) -> Option<char> {
|
||||||
if self.complement {
|
if self.complement {
|
||||||
let next = if self.squeeze_set.iter().any(|c| c.eq(¤t)) {
|
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<T, R, W>(input: &mut R, output: &mut W, mut translator: T)
|
pub fn translate_input_new<T, R, W>(input: &mut R, output: &mut W, mut translator: T)
|
||||||
where
|
where
|
||||||
T: SymbolTranslatorNew,
|
T: SymbolTranslator,
|
||||||
R: BufRead,
|
R: BufRead,
|
||||||
W: Write,
|
W: Write,
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,10 +18,10 @@ mod operation;
|
||||||
|
|
||||||
use clap::{crate_version, App, Arg};
|
use clap::{crate_version, App, Arg};
|
||||||
use nom::AsBytes;
|
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 std::io::{stdin, stdout, BufReader, BufWriter};
|
||||||
|
|
||||||
use crate::operation::DeleteOperationNew;
|
use crate::operation::DeleteOperation;
|
||||||
use uucore::InvalidEncodingHandling;
|
use uucore::InvalidEncodingHandling;
|
||||||
|
|
||||||
static ABOUT: &str = "translate or delete characters";
|
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 mut delete_writer = BufWriter::new(&mut delete_buffer);
|
||||||
let delete_op =
|
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);
|
translate_input_new(&mut locked_stdin, &mut delete_writer, delete_op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let mut squeeze_reader = BufReader::new(delete_buffer.as_bytes());
|
let mut squeeze_reader = BufReader::new(delete_buffer.as_bytes());
|
||||||
let squeeze_op =
|
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);
|
translate_input_new(&mut squeeze_reader, &mut buffered_stdout, squeeze_op);
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
translate_input_new(&mut locked_stdin, &mut buffered_stdout, op);
|
||||||
}
|
}
|
||||||
} else if squeeze_flag {
|
} else if squeeze_flag {
|
||||||
if sets.len() < 2 {
|
if sets.len() < 2 {
|
||||||
let op =
|
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);
|
translate_input_new(&mut locked_stdin, &mut buffered_stdout, op);
|
||||||
} else {
|
} else {
|
||||||
let mut translate_buffer = vec![];
|
let mut translate_buffer = vec![];
|
||||||
{
|
{
|
||||||
let mut writer = BufWriter::new(&mut translate_buffer);
|
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[0]),
|
||||||
Sequence::parse_set_string(&sets[1]),
|
Sequence::parse_set_string(&sets[1]),
|
||||||
truncate_set1_flag,
|
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 mut reader = BufReader::new(translate_buffer.as_bytes());
|
||||||
let squeeze_op =
|
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);
|
translate_input_new(&mut reader, &mut buffered_stdout, squeeze_op);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let op = TranslateOperationNew::new(
|
let op = TranslateOperation::new(
|
||||||
Sequence::parse_set_string(&sets[0]),
|
Sequence::parse_set_string(&sets[0]),
|
||||||
Sequence::parse_set_string(&sets[1]),
|
Sequence::parse_set_string(&sets[1]),
|
||||||
truncate_set1_flag,
|
truncate_set1_flag,
|
||||||
|
|
Loading…
Reference in a new issue