Skip to content

Commit 3be0749

Browse files
committed
Simplify filter_words
1 parent 6986618 commit 3be0749

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

forth/src/lib.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ impl Forth {
4646
}
4747

4848
fn filter_words(&mut self) {
49-
self.text = self.text.chars().fold(String::new(), |mut acc, chr| {
50-
if chr.is_whitespace() || chr.is_control() {
51-
acc.push(' ');
52-
} else {
53-
acc.push(chr)
54-
}
55-
acc
56-
})
49+
self.text = self
50+
.text
51+
.replace(|chr: char| chr.is_whitespace() || chr.is_control(), " ")
5752
}
5853

5954
pub fn eval(&mut self, input: &str) -> ForthResult {

0 commit comments

Comments
 (0)