mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 15:07:47 +00:00
refactor/polish ~ fix cargo clippy
complaints (unneeded ref for copiable)
This commit is contained in:
parent
bc558f301a
commit
1216378c72
4 changed files with 20 additions and 20 deletions
|
@ -17,7 +17,7 @@ pub fn err_msg(msg: &str) {
|
|||
// by default stdout only flushes
|
||||
// to console when a newline is passed.
|
||||
#[allow(unused_must_use)]
|
||||
pub fn flush_char(c: &char) {
|
||||
pub fn flush_char(c: char) {
|
||||
print!("{}", c);
|
||||
stdout().flush();
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ impl UnescapedText {
|
|||
// lazy branch eval
|
||||
// remember this fn could be called
|
||||
// many times in a single exec through %b
|
||||
cli::flush_char(&ch);
|
||||
cli::flush_char(ch);
|
||||
tmp_str.push(ch);
|
||||
}
|
||||
'\\' => {
|
||||
|
@ -210,7 +210,7 @@ impl UnescapedText {
|
|||
x if x == '%' && !subs_mode => {
|
||||
if let Some(follow) = it.next() {
|
||||
if follow == '%' {
|
||||
cli::flush_char(&ch);
|
||||
cli::flush_char(ch);
|
||||
tmp_str.push(ch);
|
||||
} else {
|
||||
it.put_back(follow);
|
||||
|
@ -223,7 +223,7 @@ impl UnescapedText {
|
|||
}
|
||||
}
|
||||
_ => {
|
||||
cli::flush_char(&ch);
|
||||
cli::flush_char(ch);
|
||||
tmp_str.push(ch);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -560,8 +560,8 @@ fn is_seekable<T: Seek>(file: &mut T) -> bool {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn print_byte<T: Write>(stdout: &mut T, ch: &u8) {
|
||||
if let Err(err) = stdout.write(&[*ch]) {
|
||||
fn print_byte<T: Write>(stdout: &mut T, ch: u8) {
|
||||
if let Err(err) = stdout.write(&[ch]) {
|
||||
crash!(1, "{}", err);
|
||||
}
|
||||
}
|
||||
|
|
28
src/tr/tr.rs
28
src/tr/tr.rs
|
@ -33,7 +33,7 @@ static VERSION: &str = env!("CARGO_PKG_VERSION");
|
|||
const BUFFER_LEN: usize = 1024;
|
||||
|
||||
trait SymbolTranslator {
|
||||
fn translate(&self, c: &char, prev_c: &char) -> Option<char>;
|
||||
fn translate(&self, c: char, prev_c: char) -> Option<char>;
|
||||
}
|
||||
|
||||
struct DeleteOperation {
|
||||
|
@ -51,10 +51,10 @@ impl DeleteOperation {
|
|||
}
|
||||
|
||||
impl SymbolTranslator for DeleteOperation {
|
||||
fn translate(&self, c: &char, _prev_c: &char) -> Option<char> {
|
||||
let uc = *c as usize;
|
||||
fn translate(&self, c: char, _prev_c: char) -> Option<char> {
|
||||
let uc = c as usize;
|
||||
if self.complement == self.bset.contains(uc) {
|
||||
Some(*c)
|
||||
Some(c)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -76,11 +76,11 @@ impl SqueezeOperation {
|
|||
}
|
||||
|
||||
impl SymbolTranslator for SqueezeOperation {
|
||||
fn translate(&self, c: &char, prev_c: &char) -> Option<char> {
|
||||
if *prev_c == *c && self.complement != self.squeeze_set.contains(*c as usize) {
|
||||
fn translate(&self, c: char, prev_c: char) -> Option<char> {
|
||||
if prev_c == c && self.complement != self.squeeze_set.contains(c as usize) {
|
||||
None
|
||||
} else {
|
||||
Some(*c)
|
||||
Some(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,13 +106,13 @@ impl DeleteAndSqueezeOperation {
|
|||
}
|
||||
|
||||
impl SymbolTranslator for DeleteAndSqueezeOperation {
|
||||
fn translate(&self, c: &char, prev_c: &char) -> Option<char> {
|
||||
if self.complement != self.delete_set.contains(*c as usize)
|
||||
|| *prev_c == *c && self.squeeze_set.contains(*c as usize)
|
||||
fn translate(&self, c: char, prev_c: char) -> Option<char> {
|
||||
if self.complement != self.delete_set.contains(c as usize)
|
||||
|| prev_c == c && self.squeeze_set.contains(c as usize)
|
||||
{
|
||||
None
|
||||
} else {
|
||||
Some(*c)
|
||||
Some(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,8 +140,8 @@ impl TranslateOperation {
|
|||
}
|
||||
|
||||
impl SymbolTranslator for TranslateOperation {
|
||||
fn translate(&self, c: &char, _prev_c: &char) -> Option<char> {
|
||||
Some(*self.translate_map.get(&(*c as usize)).unwrap_or(c))
|
||||
fn translate(&self, c: char, _prev_c: char) -> Option<char> {
|
||||
Some(*self.translate_map.get(&(c as usize)).unwrap_or(&c))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ fn translate_input<T: SymbolTranslator>(
|
|||
{
|
||||
// isolation to make borrow checker happy
|
||||
let filtered = buf.chars().filter_map(|c| {
|
||||
let res = translator.translate(&c, &prev_c);
|
||||
let res = translator.translate(c, prev_c);
|
||||
if res.is_some() {
|
||||
prev_c = c;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue