libgir/writer/
untabber.rs
1use std::io::{Result, Write};
2
3use super::TAB;
4
5pub struct Untabber {
6 orig: Box<dyn Write>,
7}
8
9impl Untabber {
10 pub fn new(orig: Box<dyn Write>) -> Self {
11 Self { orig }
12 }
13}
14
15impl Write for Untabber {
16 fn write(&mut self, buf: &[u8]) -> Result<usize> {
17 let mut chunks = buf.split(|b| b == &b'\t').peekable();
18 while let Some(chunk) = chunks.next() {
19 self.orig.write_all(chunk)?;
20 if chunks.peek().is_some() {
21 self.orig.write_all(TAB.as_bytes())?;
22 } else {
23 break;
24 }
25 }
26 Ok(buf.len())
27 }
28 fn flush(&mut self) -> Result<()> {
29 self.orig.flush()
30 }
31}