Added ignore-invalid-args: (default feature flag) Invalid utf8 arguments are ignored from the input arguments (as they are from the stdin lines.) If disabled, the invalid arg is kept and invalid utf8 characters are replaced with the unicode "invalid character" character instead.

Fortune for reverse's current commit: Curse − 凶
master
Avril 2 years ago
parent 0a78bcfd55
commit 5f8d472483
Signed by: flanchan
GPG Key ID: 284488987C31F630

2
Cargo.lock generated

@ -4,4 +4,4 @@ version = 3
[[package]]
name = "reverse"
version = "0.2.1"
version = "0.3.0"

@ -1,13 +1,13 @@
[package]
name = "reverse"
version = "0.2.1"
version = "0.3.0"
authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["output-lines", "buffer-output", "ignore-output-errors"]
default = ["output-lines", "buffer-output", "ignore-output-errors", "ignore-invalid-args"]
# Output as lines instead of `["2", "1", "0"]`
output-lines = []
@ -22,10 +22,14 @@ buffer-output = []
# Disable this if you are writing to a faulty device or expect some output operations to stdout to fail.
ignore-output-errors = []
# Ignore invalid arguments instead of removing invalid UTF8 characters if they exist in the argument
ignore-invalid-args = []
[profile.release]
opt-level = 3
lto = "fat"
codegen-units = 1
strip=true
#panic="abort" # XXX: This doesn't remove panic handler, for some reason...
[dependencies]

@ -30,20 +30,25 @@ fn binsearch<'a, V: ?Sized, T: PartialEq<V> + 'a>(slice: &'a [T], find: &V) -> O
fn collect_input() -> Box<dyn Iterator<Item=String> + 'static>
{
//! TODO: Use non-panicking functions for both reading lines and reading args, just skip invalid lines/args
// TODO: Use non-panicking functions for both reading lines and reading args, just skip invalid lines/args
if std::env::args_os().len() <= 1 {
use std::io::{
self,
BufRead,
};
// No args, collect stdin lines
Box::new(io::BufReader::new(io::stdin()
.lock())
Box::new(io::stdin()
.lock()
.lines()
.filter_map(Result::ok))
} else {
// Has arguments, return them
Box::new(std::env::args().skip(1))
if cfg!(feature="ignore-invalid-args") {
Box::new(std::env::args_os().skip(1).filter_map(|os| os.into_string().ok()))
} else {
Box::new(std::env::args_os().skip(1).map(|os| os.to_string_lossy().into_owned()))
}
}
}

Loading…
Cancel
Save