summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-07-19 22:04:18 +0300
committerLars Wirzenius <liw@liw.fi>2018-07-19 22:04:18 +0300
commitf0906d4b7601d08e3635883997a32982abb5f124 (patch)
tree717afcc331fcb1f6b5375b621b1af9c7fc6aba86
parent0cef25cad181c03eb9e9e4b10f697aca1ccb74a5 (diff)
downloadwordfreq-f0906d4b7601d08e3635883997a32982abb5f124.tar.gz
Change: use a String to buffer the chars
-rw-r--r--src/main.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index b0d0d03..d12332c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -25,17 +25,15 @@ fn print_words(reader: &mut io::BufReader<File>) -> io::Result<()> {
fn print_words_in_line(line: &str) {
- let mut was_in_word = false;
+ let mut word = String::new();
for c in line.chars() {
- let letter = c.is_alphabetic();
- if letter {
- was_in_word = true;
- print!("{}", c);
+ if c.is_alphabetic() {
+ word.push(c);
} else {
- if was_in_word {
- println!("");
+ if !word.is_empty() {
+ println!("{}", word);
}
- was_in_word = false;
+ word.clear();
}
}
}