mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 15:07:47 +00:00
refactor/polish ~ fix cargo clippy
complaints (loop/match => while let)
This commit is contained in:
parent
98039f176d
commit
fd8e5acd57
2 changed files with 98 additions and 108 deletions
|
@ -90,16 +90,9 @@ fn get_inprefix(str_in: &str, field_type: &FieldType) -> InPrefix {
|
|||
let mut topchar = str_it.next();
|
||||
// skip spaces and ensure topchar is the first non-space char
|
||||
// (or None if none exists)
|
||||
loop {
|
||||
match topchar {
|
||||
Some(' ') => {
|
||||
ret.offset += 1;
|
||||
topchar = str_it.next();
|
||||
}
|
||||
_ => {
|
||||
break;
|
||||
}
|
||||
}
|
||||
while let Some(' ') = topchar {
|
||||
ret.offset += 1;
|
||||
topchar = str_it.next();
|
||||
}
|
||||
// parse sign
|
||||
match topchar {
|
||||
|
|
193
src/seq/seq.rs
193
src/seq/seq.rs
|
@ -41,106 +41,103 @@ fn escape_sequences(s: &str) -> String {
|
|||
fn parse_options(args: Vec<String>, options: &mut SeqOptions) -> Result<Vec<String>, i32> {
|
||||
let mut seq_args = vec![];
|
||||
let mut iter = args.into_iter().skip(1);
|
||||
loop {
|
||||
match iter.next() {
|
||||
Some(arg) => match &arg[..] {
|
||||
"--help" | "-h" => {
|
||||
print_help();
|
||||
return Err(0);
|
||||
}
|
||||
"--version" | "-V" => {
|
||||
print_version();
|
||||
return Err(0);
|
||||
}
|
||||
"-s" | "--separator" => match iter.next() {
|
||||
Some(sep) => options.separator = sep,
|
||||
None => {
|
||||
show_error!("expected a separator after {}", arg);
|
||||
return Err(1);
|
||||
}
|
||||
},
|
||||
"-t" | "--terminator" => match iter.next() {
|
||||
Some(term) => options.terminator = Some(term),
|
||||
None => {
|
||||
show_error!("expected a terminator after '{}'", arg);
|
||||
return Err(1);
|
||||
}
|
||||
},
|
||||
"-w" | "--widths" => options.widths = true,
|
||||
"--" => {
|
||||
seq_args.extend(iter);
|
||||
break;
|
||||
}
|
||||
_ => {
|
||||
if arg.len() > 1 && arg.starts_with('-') {
|
||||
let argptr: *const String = &arg; // escape from the borrow checker
|
||||
let mut chiter = unsafe { &(*argptr)[..] }.chars().skip(1);
|
||||
let mut ch = ' ';
|
||||
while match chiter.next() {
|
||||
Some(m) => {
|
||||
ch = m;
|
||||
true
|
||||
}
|
||||
None => false,
|
||||
} {
|
||||
match ch {
|
||||
'h' => {
|
||||
print_help();
|
||||
return Err(0);
|
||||
}
|
||||
'V' => {
|
||||
print_version();
|
||||
return Err(0);
|
||||
}
|
||||
's' => match iter.next() {
|
||||
Some(sep) => {
|
||||
options.separator = sep;
|
||||
let next = chiter.next();
|
||||
if next.is_some() {
|
||||
show_error!(
|
||||
"unexpected character ('{}')",
|
||||
next.unwrap()
|
||||
);
|
||||
return Err(1);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
show_error!("expected a separator after {}", arg);
|
||||
return Err(1);
|
||||
}
|
||||
},
|
||||
't' => match iter.next() {
|
||||
Some(term) => {
|
||||
options.terminator = Some(term);
|
||||
let next = chiter.next();
|
||||
if next.is_some() {
|
||||
show_error!(
|
||||
"unexpected character ('{}')",
|
||||
next.unwrap()
|
||||
);
|
||||
return Err(1);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
show_error!("expected a terminator after {}", arg);
|
||||
return Err(1);
|
||||
}
|
||||
},
|
||||
'w' => options.widths = true,
|
||||
_ => {
|
||||
seq_args.push(arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
seq_args.push(arg);
|
||||
}
|
||||
while let Some(arg) = iter.next() {
|
||||
match &arg[..] {
|
||||
"--help" | "-h" => {
|
||||
print_help();
|
||||
return Err(0);
|
||||
}
|
||||
"--version" | "-V" => {
|
||||
print_version();
|
||||
return Err(0);
|
||||
}
|
||||
"-s" | "--separator" => match iter.next() {
|
||||
Some(sep) => options.separator = sep,
|
||||
None => {
|
||||
show_error!("expected a separator after {}", arg);
|
||||
return Err(1);
|
||||
}
|
||||
},
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
"-t" | "--terminator" => match iter.next() {
|
||||
Some(term) => options.terminator = Some(term),
|
||||
None => {
|
||||
show_error!("expected a terminator after '{}'", arg);
|
||||
return Err(1);
|
||||
}
|
||||
},
|
||||
"-w" | "--widths" => options.widths = true,
|
||||
"--" => {
|
||||
seq_args.extend(iter);
|
||||
break;
|
||||
}
|
||||
_ => {
|
||||
if arg.len() > 1 && arg.starts_with('-') {
|
||||
let argptr: *const String = &arg; // escape from the borrow checker
|
||||
let mut chiter = unsafe { &(*argptr)[..] }.chars().skip(1);
|
||||
let mut ch = ' ';
|
||||
while match chiter.next() {
|
||||
Some(m) => {
|
||||
ch = m;
|
||||
true
|
||||
}
|
||||
None => false,
|
||||
} {
|
||||
match ch {
|
||||
'h' => {
|
||||
print_help();
|
||||
return Err(0);
|
||||
}
|
||||
'V' => {
|
||||
print_version();
|
||||
return Err(0);
|
||||
}
|
||||
's' => match iter.next() {
|
||||
Some(sep) => {
|
||||
options.separator = sep;
|
||||
let next = chiter.next();
|
||||
if next.is_some() {
|
||||
show_error!(
|
||||
"unexpected character ('{}')",
|
||||
next.unwrap()
|
||||
);
|
||||
return Err(1);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
show_error!("expected a separator after {}", arg);
|
||||
return Err(1);
|
||||
}
|
||||
},
|
||||
't' => match iter.next() {
|
||||
Some(term) => {
|
||||
options.terminator = Some(term);
|
||||
let next = chiter.next();
|
||||
if next.is_some() {
|
||||
show_error!(
|
||||
"unexpected character ('{}')",
|
||||
next.unwrap()
|
||||
);
|
||||
return Err(1);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
show_error!("expected a terminator after {}", arg);
|
||||
return Err(1);
|
||||
}
|
||||
},
|
||||
'w' => options.widths = true,
|
||||
_ => {
|
||||
seq_args.push(arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
seq_args.push(arg);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
Ok(seq_args)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue