Add printable CLI to strip unwanted characters from email.

This commit is contained in:
2022-12-29 10:30:19 -08:00
parent 7685b0e5b2
commit af87a3cade
4 changed files with 77 additions and 16 deletions

27
src/bin/printable.rs Normal file
View 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(())
}