solve panicking with flag é

This commit is contained in:
primardj 2024-04-06 11:48:48 +01:00
parent 9ec956a049
commit 14c01eb796
2 changed files with 12 additions and 5 deletions

View file

@ -55,9 +55,14 @@ fn main() {
i += 1; i += 1;
} }
else { else {
if val.len() == 2 { if val.len() >= 2 {
println!("sv: illegal option -- {}", val.chars().nth(1).unwrap() ); let mut j = 0;
// TODO: thread NOT pannic if it is not an ASCII character. for ch in val.chars() {
if j == 1 {
println!("sv: illegal option -- {}", ch );
}
j += 1;
}
} }
parser::misc::usage(); parser::misc::usage();
exit(100); exit(100);

View file

@ -52,6 +52,7 @@ pub fn parse_args(args: Vec<String>) -> Vec<String>{
} }
} }
return parser; return parser;
} }
@ -79,12 +80,13 @@ pub fn parse_args_1(arg: &String) -> String{
//println!("{}", ch1); //println!("{}", ch1);
if ch1 == '-' && arg.len() >= 2{ if ch1 == '-' && arg.len() >= 2{
return (&arg[..2]).to_string() let retour = &arg.chars().collect::<Vec<_>>()[..2];
return retour.into_iter().collect();
} else if ch1 == '-' { } else if ch1 == '-' {
return ch1.to_string() return ch1.to_string()
} }
println!("{}",arg); //println!("{}",arg);
return "".to_string() return "".to_string()