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();
|
let mut topchar = str_it.next();
|
||||||
// skip spaces and ensure topchar is the first non-space char
|
// skip spaces and ensure topchar is the first non-space char
|
||||||
// (or None if none exists)
|
// (or None if none exists)
|
||||||
loop {
|
while let Some(' ') = topchar {
|
||||||
match topchar {
|
ret.offset += 1;
|
||||||
Some(' ') => {
|
topchar = str_it.next();
|
||||||
ret.offset += 1;
|
|
||||||
topchar = str_it.next();
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// parse sign
|
// parse sign
|
||||||
match topchar {
|
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> {
|
fn parse_options(args: Vec<String>, options: &mut SeqOptions) -> Result<Vec<String>, i32> {
|
||||||
let mut seq_args = vec![];
|
let mut seq_args = vec![];
|
||||||
let mut iter = args.into_iter().skip(1);
|
let mut iter = args.into_iter().skip(1);
|
||||||
loop {
|
while let Some(arg) = iter.next() {
|
||||||
match iter.next() {
|
match &arg[..] {
|
||||||
Some(arg) => match &arg[..] {
|
"--help" | "-h" => {
|
||||||
"--help" | "-h" => {
|
print_help();
|
||||||
print_help();
|
return Err(0);
|
||||||
return Err(0);
|
}
|
||||||
}
|
"--version" | "-V" => {
|
||||||
"--version" | "-V" => {
|
print_version();
|
||||||
print_version();
|
return Err(0);
|
||||||
return Err(0);
|
}
|
||||||
}
|
"-s" | "--separator" => match iter.next() {
|
||||||
"-s" | "--separator" => match iter.next() {
|
Some(sep) => options.separator = sep,
|
||||||
Some(sep) => options.separator = sep,
|
None => {
|
||||||
None => {
|
show_error!("expected a separator after {}", arg);
|
||||||
show_error!("expected a separator after {}", arg);
|
return Err(1);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
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)
|
Ok(seq_args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue