From 09f6509050f24e54c9859e0905e8b6731d91f39f Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Wed, 29 Jul 2015 00:01:46 +0200 Subject: implement sort and dedup of logs --- src/format/energymech.rs | 12 +++++++----- src/format/weechat3.rs | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'src/format') diff --git a/src/format/energymech.rs b/src/format/energymech.rs index 0e46dce..df48318 100644 --- a/src/format/energymech.rs +++ b/src/format/energymech.rs @@ -31,7 +31,7 @@ static TIME_FORMAT: &'static str = "%H:%M:%S"; pub struct Iter<'a, R: 'a> where R: BufRead { context: &'a Context, input: R, - buffer: String + buffer: Vec } impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { @@ -54,18 +54,20 @@ impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { loop { self.buffer.clear(); - match self.input.read_line(&mut self.buffer) { + match self.input.read_until(b'\n', &mut self.buffer) { Ok(0) | Err(_) => return None, Ok(_) => () } + let buffer = String::from_utf8_lossy(&self.buffer); + let mut split_tokens: Vec = Vec::new(); - let tokens = self.buffer.split( |c: char| { + let tokens = buffer.split( |c: char| { if c.is_whitespace() { split_tokens.push(c); true } else { false } }).collect::>(); if log_enabled!(Info) { - info!("Original: `{}`", self.buffer); + info!("Original: `{}`", buffer); info!("Parsing: {:?}", tokens); } @@ -157,7 +159,7 @@ impl<'a, R: 'a> Decode<'a, R> for Energymech where R: BufRead { Iter { context: context, input: input, - buffer: String::new() + buffer: Vec::new() } } } diff --git a/src/format/weechat3.rs b/src/format/weechat3.rs index 3ff781c..e733a38 100644 --- a/src/format/weechat3.rs +++ b/src/format/weechat3.rs @@ -29,7 +29,7 @@ static TIME_DATE_FORMAT: &'static str = "%Y-%m-%d %H:%M:%S"; pub struct Iter<'a, R: 'a> where R: BufRead { context: &'a Context, input: R, - buffer: String + buffer: Vec } impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { @@ -41,18 +41,20 @@ impl<'a, R: 'a> Iterator for Iter<'a, R> where R: BufRead { loop { self.buffer.clear(); - match self.input.read_line(&mut self.buffer) { + match self.input.read_until(b'\n', &mut self.buffer) { Ok(0) | Err(_) => return None, Ok(_) => () } + let buffer = String::from_utf8_lossy(&self.buffer); + let mut split_tokens: Vec = Vec::new(); - let tokens = self.buffer.split(|c: char| { + let tokens = buffer.split(|c: char| { if c.is_whitespace() { split_tokens.push(c); true } else { false } }).collect::>(); if log_enabled!(Info) { - info!("Original: `{}`", self.buffer); + info!("Original: `{}`", buffer); info!("Parsing: {:?}", tokens); } @@ -143,7 +145,7 @@ impl<'a, I: 'a> Decode<'a, I> for Weechat3 where I: BufRead { Iter { context: context, input: input, - buffer: String::new() + buffer: Vec::new() } } } -- cgit v1.2.3