Remove empty lines when reading from an input file

This commit is contained in:
Kenneth Gitere 2021-02-03 07:39:51 +03:00
parent 3d56023592
commit 08f847531f

View file

@ -20,7 +20,11 @@ fn main() {
if let Ok(mut file) = File::open(file_name) { if let Ok(mut file) = File::open(file_name) {
let mut content = String::new(); let mut content = String::new();
match file.read_to_string(&mut content) { match file.read_to_string(&mut content) {
Ok(_) => content.lines().map(|line| line.to_owned()).collect(), Ok(_) => content
.lines()
.filter(|line| !line.is_empty())
.map(|line| line.to_owned())
.collect(),
Err(_) => vec![], Err(_) => vec![],
} }
} else { } else {
@ -32,7 +36,10 @@ fn main() {
}; };
if let Some(vals) = arg_matches.values_of("urls") { if let Some(vals) = arg_matches.values_of("urls") {
urls.extend(vals.map(|val| val.to_string())); urls.extend(
vals.filter(|val| !val.is_empty())
.map(|val| val.to_string()),
);
} }
if !urls.is_empty() { if !urls.is_empty() {