forked from bonsai/harakit
fop(1): adds the ability to use any string as a delimiter
This commit is contained in:
parent
9093b06166
commit
2dd6c0ded7
12
src/fop.rs
12
src/fop.rs
@ -32,18 +32,12 @@ use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE };
|
||||
|
||||
fn main() {
|
||||
let argv = args().collect::<Vec<String>>();
|
||||
let mut d = '␞';
|
||||
let mut d = "␞".to_owned();
|
||||
let mut arg_parser = Parser::new(&argv, "d:");
|
||||
|
||||
while let Some(opt) = arg_parser.next() {
|
||||
match opt {
|
||||
Ok(Opt('d', Some(arg))) => {
|
||||
let arg_char = arg.chars().collect::<Vec<char>>();
|
||||
if arg_char.len() > 1 {
|
||||
eprintln!("{}: {}: Not a character.", argv[0], arg);
|
||||
exit(EX_USAGE);
|
||||
} else { d = arg_char[0]; }
|
||||
},
|
||||
Ok(Opt('d', Some(arg))) => d = arg,
|
||||
_ => {},
|
||||
};
|
||||
}
|
||||
@ -63,7 +57,7 @@ fn main() {
|
||||
|
||||
let mut buf = String::new();
|
||||
let _ = stdin().read_to_string(&mut buf);
|
||||
let mut fields = buf.split(d).collect::<Vec<&str>>();
|
||||
let mut fields = buf.split(&d).collect::<Vec<&str>>();
|
||||
|
||||
let opts = argv
|
||||
.iter()
|
||||
|
Loading…
Reference in New Issue
Block a user