Add printable CLI to strip unwanted characters from email.
This commit is contained in:
27
src/bin/printable.rs
Normal file
27
src/bin/printable.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use std::{io, io::Read};
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
fn main() -> io::Result<()> {
|
||||
let re = Regex::new("[^[[:print:]]\n]").expect("invalid regex");
|
||||
let mut buffer = String::new();
|
||||
io::stdin().read_to_string(&mut buffer)?;
|
||||
let buffer = re.replace_all(&buffer, "");
|
||||
|
||||
let mut last_c = 0;
|
||||
for l in buffer.lines() {
|
||||
let c = l
|
||||
.as_bytes()
|
||||
.iter()
|
||||
.filter(|b| match b {
|
||||
b' ' | b'\t' => false,
|
||||
_ => true,
|
||||
})
|
||||
.count();
|
||||
if !(c == 0 && last_c == 0) {
|
||||
println!("{l}");
|
||||
}
|
||||
last_c = c;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user