mirror of
https://github.com/uutils/coreutils
synced 2024-12-18 09:03:14 +00:00
Fixed clippy issues
Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
This commit is contained in:
parent
5bf0197da5
commit
3fa56eabce
3 changed files with 20 additions and 29 deletions
|
@ -75,7 +75,7 @@ impl Sequence {
|
||||||
Sequence::CharRepeat(c, n) => Box::new(std::iter::repeat(*c).take(*n)),
|
Sequence::CharRepeat(c, n) => Box::new(std::iter::repeat(*c).take(*n)),
|
||||||
Sequence::Alnum => Box::new(('0'..='9').chain('A'..='Z').chain('a'..='z')),
|
Sequence::Alnum => Box::new(('0'..='9').chain('A'..='Z').chain('a'..='z')),
|
||||||
Sequence::Alpha => Box::new(('A'..='Z').chain('a'..='z')),
|
Sequence::Alpha => Box::new(('A'..='Z').chain('a'..='z')),
|
||||||
Sequence::Blank => Box::new(unicode_table::BLANK.into_iter().cloned()),
|
Sequence::Blank => Box::new(unicode_table::BLANK.iter().cloned()),
|
||||||
Sequence::Control => Box::new(
|
Sequence::Control => Box::new(
|
||||||
(0..=31)
|
(0..=31)
|
||||||
.chain(std::iter::once(127))
|
.chain(std::iter::once(127))
|
||||||
|
@ -113,7 +113,7 @@ impl Sequence {
|
||||||
.chain(123..=126)
|
.chain(123..=126)
|
||||||
.flat_map(char::from_u32),
|
.flat_map(char::from_u32),
|
||||||
),
|
),
|
||||||
Sequence::Space => Box::new(unicode_table::SPACES.into_iter().cloned()),
|
Sequence::Space => Box::new(unicode_table::SPACES.iter().cloned()),
|
||||||
Sequence::Upper => Box::new('A'..='Z'),
|
Sequence::Upper => Box::new('A'..='Z'),
|
||||||
Sequence::Xdigit => Box::new(('0'..='9').chain('A'..='F').chain('a'..='f')),
|
Sequence::Xdigit => Box::new(('0'..='9').chain('A'..='F').chain('a'..='f')),
|
||||||
}
|
}
|
||||||
|
@ -129,12 +129,7 @@ impl Sequence {
|
||||||
let set1 = Sequence::from_str(set1_str)?;
|
let set1 = Sequence::from_str(set1_str)?;
|
||||||
let set2 = Sequence::from_str(set2_str)?;
|
let set2 = Sequence::from_str(set2_str)?;
|
||||||
|
|
||||||
let is_char_star = |s: &&Sequence| -> bool {
|
let is_char_star = |s: &&Sequence| -> bool { matches!(s, Sequence::CharStar(_)) };
|
||||||
match s {
|
|
||||||
Sequence::CharStar(_) => true,
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let set1_star_count = set1.iter().filter(is_char_star).count();
|
let set1_star_count = set1.iter().filter(is_char_star).count();
|
||||||
if set1_star_count == 0 {
|
if set1_star_count == 0 {
|
||||||
let set2_star_count = set2.iter().filter(is_char_star).count();
|
let set2_star_count = set2.iter().filter(is_char_star).count();
|
||||||
|
@ -143,10 +138,9 @@ impl Sequence {
|
||||||
Sequence::CharStar(c) => Some(c),
|
Sequence::CharStar(c) => Some(c),
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
let mut partition = set2.as_slice().split(|s| match s {
|
let mut partition = set2
|
||||||
Sequence::CharStar(_) => true,
|
.as_slice()
|
||||||
_ => false,
|
.split(|s| matches!(s, Sequence::CharStar(_)));
|
||||||
});
|
|
||||||
let set1_len = set1.iter().flat_map(Sequence::flatten).count();
|
let set1_len = set1.iter().flat_map(Sequence::flatten).count();
|
||||||
let set2_len = set2
|
let set2_len = set2
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -199,7 +193,7 @@ impl Sequence {
|
||||||
if truncate_set1_flag {
|
if truncate_set1_flag {
|
||||||
set1_solved.truncate(set2_solved.len());
|
set1_solved.truncate(set2_solved.len());
|
||||||
}
|
}
|
||||||
return Ok((set1_solved, set2_solved));
|
Ok((set1_solved, set2_solved))
|
||||||
} else {
|
} else {
|
||||||
Err(BadSequence::MultipleCharRepeatInSet2)
|
Err(BadSequence::MultipleCharRepeatInSet2)
|
||||||
}
|
}
|
||||||
|
@ -211,7 +205,7 @@ impl Sequence {
|
||||||
|
|
||||||
impl Sequence {
|
impl Sequence {
|
||||||
pub fn from_str(input: &str) -> Result<Vec<Sequence>, BadSequence> {
|
pub fn from_str(input: &str) -> Result<Vec<Sequence>, BadSequence> {
|
||||||
let result = many0(alt((
|
many0(alt((
|
||||||
alt((
|
alt((
|
||||||
Sequence::parse_char_range,
|
Sequence::parse_char_range,
|
||||||
Sequence::parse_char_star,
|
Sequence::parse_char_star,
|
||||||
|
@ -244,8 +238,7 @@ impl Sequence {
|
||||||
.map(|(_, r)| r)
|
.map(|(_, r)| r)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect::<Result<Vec<_>, _>>();
|
.collect::<Result<Vec<_>, _>>()
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_backslash(input: &str) -> IResult<&str, char> {
|
fn parse_backslash(input: &str) -> IResult<&str, char> {
|
||||||
|
@ -442,15 +435,14 @@ pub struct TranslateOperationStandard {
|
||||||
|
|
||||||
impl TranslateOperationStandard {
|
impl TranslateOperationStandard {
|
||||||
fn new(set1: Vec<char>, set2: Vec<char>) -> Result<TranslateOperationStandard, String> {
|
fn new(set1: Vec<char>, set2: Vec<char>) -> Result<TranslateOperationStandard, String> {
|
||||||
if let Some(fallback) = set2.last().map(|s| *s) {
|
if let Some(fallback) = set2.last().copied() {
|
||||||
Ok(TranslateOperationStandard {
|
Ok(TranslateOperationStandard {
|
||||||
translation_map: set1
|
translation_map: set1
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.zip(set2.into_iter().chain(std::iter::repeat(fallback)))
|
.zip(set2.into_iter().chain(std::iter::repeat(fallback)))
|
||||||
.collect::<HashMap<_, _>>(),
|
.collect::<HashMap<_, _>>(),
|
||||||
})
|
})
|
||||||
} else {
|
} else if set1.is_empty() && set2.is_empty() {
|
||||||
if set1.is_empty() && set2.is_empty() {
|
|
||||||
Ok(TranslateOperationStandard {
|
Ok(TranslateOperationStandard {
|
||||||
translation_map: HashMap::new(),
|
translation_map: HashMap::new(),
|
||||||
})
|
})
|
||||||
|
@ -459,7 +451,6 @@ impl TranslateOperationStandard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub enum TranslateOperation {
|
pub enum TranslateOperation {
|
||||||
Standard(TranslateOperationStandard),
|
Standard(TranslateOperationStandard),
|
||||||
|
|
|
@ -101,7 +101,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(first) = sets.get(0) {
|
if let Some(first) = sets.get(0) {
|
||||||
if first.ends_with(r"\") {
|
if first.ends_with('\\') {
|
||||||
show_error!("warning: an unescaped backslash at end of string is not portable");
|
show_error!("warning: an unescaped backslash at end of string is not portable");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
let mut delete_buffer = vec![];
|
let mut delete_buffer = vec![];
|
||||||
{
|
{
|
||||||
let mut delete_writer = BufWriter::new(&mut delete_buffer);
|
let mut delete_writer = BufWriter::new(&mut delete_buffer);
|
||||||
let delete_op = DeleteOperation::new(set1.clone(), complement_flag);
|
let delete_op = DeleteOperation::new(set1, complement_flag);
|
||||||
translate_input(&mut locked_stdin, &mut delete_writer, delete_op);
|
translate_input(&mut locked_stdin, &mut delete_writer, delete_op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -150,7 +150,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
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);
|
||||||
match TranslateOperation::new(set1.clone(), set2.clone(), complement_flag) {
|
match TranslateOperation::new(set1, set2.clone(), complement_flag) {
|
||||||
Ok(op) => translate_input(&mut locked_stdin, &mut writer, op),
|
Ok(op) => translate_input(&mut locked_stdin, &mut writer, op),
|
||||||
Err(s) => {
|
Err(s) => {
|
||||||
show_error!("{}", s);
|
show_error!("{}", s);
|
||||||
|
|
|
@ -6,5 +6,5 @@ pub static VT: char = '\u{000B}';
|
||||||
pub static FF: char = '\u{000C}';
|
pub static FF: char = '\u{000C}';
|
||||||
pub static CR: char = '\u{000D}';
|
pub static CR: char = '\u{000D}';
|
||||||
pub static SPACE: char = '\u{0020}';
|
pub static SPACE: char = '\u{0020}';
|
||||||
pub static SPACES: &'static [char] = &[HT, LF, VT, FF, CR, SPACE];
|
pub static SPACES: &[char] = &[HT, LF, VT, FF, CR, SPACE];
|
||||||
pub static BLANK: &'static [char] = &[SPACE, HT];
|
pub static BLANK: &[char] = &[SPACE, HT];
|
||||||
|
|
Loading…
Reference in a new issue