mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
squash some repeated match blocks
This commit is contained in:
parent
de07df5992
commit
41e2197188
11 changed files with 26 additions and 64 deletions
|
|
@ -372,9 +372,10 @@ fn cut_files(mut filenames: Vec<String>, mode: &Mode) -> UResult<()> {
|
|||
.map_err_context(|| filename.maybe_quote().to_string())
|
||||
.and_then(|file| {
|
||||
match &mode {
|
||||
Mode::Bytes(ref ranges, ref opts) => cut_bytes(file, ranges, opts),
|
||||
Mode::Characters(ref ranges, ref opts) => cut_bytes(file, ranges, opts),
|
||||
Mode::Fields(ref ranges, ref opts) => cut_fields(file, ranges, opts),
|
||||
Mode::Bytes(ranges, opts) | Mode::Characters(ranges, opts) => {
|
||||
cut_bytes(file, ranges, opts)
|
||||
}
|
||||
Mode::Fields(ranges, opts) => cut_fields(file, ranges, opts),
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -487,14 +487,7 @@ pub fn parse_conv_flag_input(matches: &Matches) -> Result<IConvFlags, ParseError
|
|||
fmt = Some(flag);
|
||||
}
|
||||
}
|
||||
ConvFlag::UCase => {
|
||||
if case.is_some() {
|
||||
return Err(ParseError::MultipleUCaseLCase);
|
||||
} else {
|
||||
case = Some(flag);
|
||||
}
|
||||
}
|
||||
ConvFlag::LCase => {
|
||||
ConvFlag::UCase | ConvFlag::LCase => {
|
||||
if case.is_some() {
|
||||
return Err(ParseError::MultipleUCaseLCase);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -444,10 +444,10 @@ impl Error for DuError {}
|
|||
impl UError for DuError {
|
||||
fn code(&self) -> i32 {
|
||||
match self {
|
||||
Self::InvalidMaxDepthArg(_) => 1,
|
||||
Self::SummarizeDepthConflict(_) => 1,
|
||||
Self::InvalidTimeStyleArg(_) => 1,
|
||||
Self::InvalidTimeArg(_) => 1,
|
||||
Self::InvalidMaxDepthArg(_)
|
||||
| Self::SummarizeDepthConflict(_)
|
||||
| Self::InvalidTimeStyleArg(_)
|
||||
| Self::InvalidTimeArg(_) => 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -302,12 +302,7 @@ fn push_token_to_either_stack(
|
|||
}
|
||||
}
|
||||
|
||||
Token::PrefixOp { .. } => {
|
||||
op_stack.push((token_idx, token.clone()));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Token::ParOpen => {
|
||||
Token::PrefixOp { .. } | Token::ParOpen => {
|
||||
op_stack.push((token_idx, token.clone()));
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -352,12 +347,7 @@ fn push_op_to_stack(
|
|||
{
|
||||
loop {
|
||||
match op_stack.last() {
|
||||
None => {
|
||||
op_stack.push((token_idx, token.clone()));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Some(&(_, Token::ParOpen)) => {
|
||||
None | Some(&(_, Token::ParOpen)) => {
|
||||
op_stack.push((token_idx, token.clone()));
|
||||
return Ok(());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,25 +82,17 @@ pub fn strings_to_tokens(strings: &[String]) -> Result<Vec<(usize, Token)>, Stri
|
|||
|
||||
":" => Token::new_infix_op(s, true, 6),
|
||||
|
||||
"*" => Token::new_infix_op(s, true, 5),
|
||||
"/" => Token::new_infix_op(s, true, 5),
|
||||
"%" => Token::new_infix_op(s, true, 5),
|
||||
"*" | "/" | "%" => Token::new_infix_op(s, true, 5),
|
||||
|
||||
"+" => Token::new_infix_op(s, true, 4),
|
||||
"-" => Token::new_infix_op(s, true, 4),
|
||||
"+" | "-" => Token::new_infix_op(s, true, 4),
|
||||
|
||||
"=" => Token::new_infix_op(s, true, 3),
|
||||
"!=" => Token::new_infix_op(s, true, 3),
|
||||
"<" => Token::new_infix_op(s, true, 3),
|
||||
">" => Token::new_infix_op(s, true, 3),
|
||||
"<=" => Token::new_infix_op(s, true, 3),
|
||||
">=" => Token::new_infix_op(s, true, 3),
|
||||
"=" | "!=" | "<" | ">" | "<=" | ">=" => Token::new_infix_op(s, true, 3),
|
||||
|
||||
"&" => Token::new_infix_op(s, true, 2),
|
||||
|
||||
"|" => Token::new_infix_op(s, true, 1),
|
||||
|
||||
"match" => Token::PrefixOp {
|
||||
"match" | "index" => Token::PrefixOp {
|
||||
arity: 2,
|
||||
value: s.clone(),
|
||||
},
|
||||
|
|
@ -108,10 +100,6 @@ pub fn strings_to_tokens(strings: &[String]) -> Result<Vec<(usize, Token)>, Stri
|
|||
arity: 3,
|
||||
value: s.clone(),
|
||||
},
|
||||
"index" => Token::PrefixOp {
|
||||
arity: 2,
|
||||
value: s.clone(),
|
||||
},
|
||||
"length" => Token::PrefixOp {
|
||||
arity: 1,
|
||||
value: s.clone(),
|
||||
|
|
|
|||
|
|
@ -81,11 +81,11 @@ impl Error for LnError {}
|
|||
impl UError for LnError {
|
||||
fn code(&self) -> i32 {
|
||||
match self {
|
||||
Self::TargetIsDirectory(_) => 1,
|
||||
Self::SomeLinksFailed => 1,
|
||||
Self::FailedToLink(_) => 1,
|
||||
Self::MissingDestination(_) => 1,
|
||||
Self::ExtraOperand(_) => 1,
|
||||
Self::TargetIsDirectory(_)
|
||||
| Self::SomeLinksFailed
|
||||
| Self::FailedToLink(_)
|
||||
| Self::MissingDestination(_)
|
||||
| Self::ExtraOperand(_) => 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,8 +150,7 @@ impl UError for LsError {
|
|||
fn code(&self) -> i32 {
|
||||
match self {
|
||||
LsError::InvalidLineWidth(_) => 2,
|
||||
LsError::IOError(_) => 1,
|
||||
LsError::IOErrorContext(_, _) => 1,
|
||||
LsError::IOError(_) | LsError::IOErrorContext(_, _) => 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1845,8 +1844,7 @@ fn get_block_size(md: &Metadata, config: &Config) -> u64 {
|
|||
// hard-coded for now - enabling setting this remains a TODO
|
||||
let ls_block_size = 1024;
|
||||
match config.size_format {
|
||||
SizeFormat::Binary => md.blocks() * 512,
|
||||
SizeFormat::Decimal => md.blocks() * 512,
|
||||
SizeFormat::Binary | SizeFormat::Decimal => md.blocks() * 512,
|
||||
SizeFormat::Bytes => md.blocks() * 512 / ls_block_size,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,14 +211,13 @@ fn eval(stack: &mut Vec<Symbol>) -> Result<bool, String> {
|
|||
})
|
||||
}
|
||||
Some(Symbol::Literal(s)) => Ok(!s.is_empty()),
|
||||
Some(Symbol::None) => Ok(false),
|
||||
Some(Symbol::None) | None => Ok(false),
|
||||
Some(Symbol::BoolOp(op)) => {
|
||||
let b = eval(stack)?;
|
||||
let a = eval(stack)?;
|
||||
|
||||
Ok(if op == "-a" { a && b } else { a || b })
|
||||
}
|
||||
None => Ok(false),
|
||||
_ => Err("expected value".to_string()),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -253,12 +253,7 @@ fn word_count_from_reader<T: WordCountable>(
|
|||
}
|
||||
if settings.show_max_line_length {
|
||||
match ch {
|
||||
'\n' => {
|
||||
total.max_line_length = max(current_len, total.max_line_length);
|
||||
current_len = 0;
|
||||
}
|
||||
// '\x0c' = '\f'
|
||||
'\r' | '\x0c' => {
|
||||
'\n' | '\r' | '\x0c' => {
|
||||
total.max_line_length = max(current_len, total.max_line_length);
|
||||
current_len = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,8 +151,7 @@ pub enum ConversionResult {
|
|||
impl ConversionResult {
|
||||
pub fn accept_any(self) -> Vec<String> {
|
||||
match self {
|
||||
Self::Complete(result) => result,
|
||||
Self::Lossy(result) => result,
|
||||
Self::Complete(result) | Self::Lossy(result) => result,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,8 +102,7 @@ impl Error for ParseSizeError {
|
|||
impl fmt::Display for ParseSizeError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
let s = match self {
|
||||
ParseSizeError::ParseFailure(s) => s,
|
||||
ParseSizeError::SizeTooBig(s) => s,
|
||||
ParseSizeError::ParseFailure(s) | ParseSizeError::SizeTooBig(s) => s,
|
||||
};
|
||||
write!(f, "{}", s)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue