From 08f847531f92badeb11856f20bd0f3102a3f07df Mon Sep 17 00:00:00 2001 From: Kenneth Gitere Date: Wed, 3 Feb 2021 07:39:51 +0300 Subject: [PATCH] Remove empty lines when reading from an input file --- src/main.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 450cf3e..e843aea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,11 @@ fn main() { if let Ok(mut file) = File::open(file_name) { let mut content = String::new(); 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![], } } else { @@ -32,7 +36,10 @@ fn main() { }; 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() {