1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Use line continuations instead of string addition

I didn't know that line continuations stripped preceding whitespace
This commit is contained in:
Jordy Dickinson 2013-12-20 22:27:49 -05:00
parent d63c268239
commit 9cfb0645e8

View file

@ -38,8 +38,8 @@ fn decode(conf: &mut Conf) {
if conf.ignore_garbage { if conf.ignore_garbage {
let standard_chars = let standard_chars =
bytes!("ABCDEFGHIJKLMNOPQRSTUVWXYZ", bytes!("ABCDEFGHIJKLMNOPQRSTUVWXYZ",
"abcdefghijklmnopqrstuvwxyz", "abcdefghijklmnopqrstuvwxyz",
"0123456789+/").map(|b| char::from_u32(*b as u32).unwrap()); "0123456789+/").map(|b| char::from_u32(*b as u32).unwrap());
to_decode = to_decode to_decode = to_decode
.trim_chars(&|c| !standard_chars.contains(&c)) .trim_chars(&|c| !standard_chars.contains(&c))
@ -87,12 +87,12 @@ fn help(conf: &Conf) {
println(""); println("");
println(conf.usage); println(conf.usage);
let msg = ~"With no FILE, or when FILE is -, read standard input.\n\n" let msg = ~"With no FILE, or when FILE is -, read standard input.\n\n\
+ "The data are encoded as described for the base64 alphabet in RFC " The data are encoded as described for the base64 alphabet in RFC \
+ "3548. When\ndecoding, the input may contain newlines in addition " 3548. When\ndecoding, the input may contain newlines in addition \
+ "to the bytes of the formal\nbase64 alphabet. Use --ignore-garbage " to the bytes of the formal\nbase64 alphabet. Use --ignore-garbage \
+ "to attempt to recover from any other\nnon-alphabet bytes in the " to attempt to recover from any other\nnon-alphabet bytes in the \
+ "encoded stream."; encoded stream.";
println(msg); println(msg);
} }
@ -128,11 +128,11 @@ impl Conf {
optflag("i", "ignore-garbage", optflag("i", "ignore-garbage",
"when decoding, ignore non-alphabetic characters"), "when decoding, ignore non-alphabetic characters"),
optopt("w", "wrap", optopt("w", "wrap",
"wrap encoded lines after COLS character (default 76, 0 to disable" "wrap encoded lines after COLS character (default 76, 0 to \
+ " wrapping)", "COLS"), disable wrapping)", "COLS"),
optflag("h", "help", "display this help text and exit"), optflag("h", "help", "display this help text and exit"),
optflag("V", "version", "output version information and exit") optflag("V", "version", "output version information and exit")
]; ];
let matches = match getopts(args.tail(), opts) { let matches = match getopts(args.tail(), opts) {
Ok(m) => m, Ok(m) => m,
Err(e) => { Err(e) => {
@ -143,8 +143,8 @@ impl Conf {
Conf { Conf {
progname: args[0].clone(), progname: args[0].clone(),
usage: usage("Base64 encode or decode FILE, or standard input, to " usage: usage("Base64 encode or decode FILE, or standard input, to \
+ "standard output.", opts), standard output.", opts),
mode: if matches.opt_present("help") { mode: if matches.opt_present("help") {
Help Help
} else if matches.opt_present("version") { } else if matches.opt_present("version") {
@ -159,15 +159,14 @@ impl Conf {
Some(s) => match from_str(s) { Some(s) => match from_str(s) {
Some(s) => s, Some(s) => s,
None => { None => {
error!("error: {:s}", error!("error: {:s}", "Argument to option 'wrap' \
"Argument to option 'wrap' improperly " improperly formatted.");
+ "formatted.");
fail!() fail!()
} }
}, },
None => 76 None => 76
}, },
input_file: if matches.free.is_empty() input_file: if matches.free.is_empty()
|| matches.free[0] == ~"-" { || matches.free[0] == ~"-" {
~stdin() as ~Reader ~stdin() as ~Reader
} else { } else {