summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2021-03-05 06:38:08 -0500
committerAdam T. Carpenter <atc@53hor.net>2021-03-05 06:38:08 -0500
commit2b23cd283cc8a25689cf6400d86309a2a1f0ffad (patch)
tree772e037f896e5f845bdfaa2d997c2edb2fe5f26e /src
parent9aefd75b5e8214e65524b8187dbc2047cc518cae (diff)
downloadtitler-2b23cd283cc8a25689cf6400d86309a2a1f0ffad.tar.xz
titler-2b23cd283cc8a25689cf6400d86309a2a1f0ffad.zip
fixed #3, benchmarks showed that buffered writing wasn't a bad idea
Diffstat (limited to 'src')
-rw-r--r--src/main.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index b26289c..fe1d0eb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
use std::collections::HashSet;
use std::env::args;
-use std::io::{stdin, BufRead, BufReader};
+use std::io::{prelude::*, stdin, stdout, BufReader, BufWriter};
const HELP_MSG: &str = "Title-Case Tool\n\
-h | --help\t\t\tPrints this message\n\
@@ -46,11 +46,18 @@ fn main() {
// gather exceptions
let exceptions: HashSet<&'static str> = EXCEPTIONS.iter().cloned().collect();
- // read input and correct lines
+ // read input, correct lines, write output
+ let mut writer = BufWriter::new(stdout());
for line in BufReader::new(stdin()).lines() {
let line = line.expect("IO error");
- println!("{}", correct_line(&line, &ignorables, &exceptions));
+ writeln!(
+ &mut writer,
+ "{}",
+ correct_line(&line, &ignorables, &exceptions)
+ )
+ .expect("Failed to write output");
}
+ writer.flush().expect("Failed to write output");
}
/// Corrects a single line (title) based on placement and exceptions.