From c10547feed8f2b62a125e54d815440768e0d4d08 Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Sat, 4 Apr 2015 23:10:47 +0200 Subject: Account for non-'blank' whitespace --- src/format/weechat3.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/format') diff --git a/src/format/weechat3.rs b/src/format/weechat3.rs index f33847e..02602e0 100644 --- a/src/format/weechat3.rs +++ b/src/format/weechat3.rs @@ -24,10 +24,10 @@ impl Iterator for Iter where R: BufRead { fn timestamp(date: &str, time: &str) -> i64 { UTC.datetime_from_str(&format!("{} {}", date, time), TIME_DATE_FORMAT).unwrap().timestamp() } - fn join(s: &[&str]) -> String { + fn join(s: &[&str], splits: &[&str]) -> String { let len = s.iter().map(|s| s.len()).sum(); - let mut out = s.iter().fold(String::with_capacity(len), - |mut s, b| { s.push_str(b); s.push(' '); s }); + let mut out = s.iter().zip(splits.iter()).fold(String::with_capacity(len), + |mut s, (b, split)| { s.push_str(b); s.push(split); s }); out.pop(); out } fn mask(s: &str) -> String { @@ -41,7 +41,8 @@ impl Iterator for Iter where R: BufRead { Ok(_) => () } - let tokens = self.buffer.split(|c: char| c.is_whitespace()).collect::>(); + let mut split_tokens = Vec::new(); + let tokens = self.buffer.split(|c: char| { split_tokens.push(c); c.is_whitespace() }).collect::>(); if log_enabled!(Info) { info!("Original: `{}`", self.buffer); info!("Parsing: {:?}", tokens); -- cgit v1.2.3