Stop SplitByChar also lowercasing the entire string. Fixes
bug #581.
It's weird that a function with this name would lowercase the whole string.
Nemo and I have checked the history and code for any justifications of the
lowercasing but we found none.
I have checked in the code if anything actually depends on SplitByChar also
lowercasing the string but I found nothing.
It would surprise me since it's not obvious from the name IMO is bad
coding practice anyway.
Bug 581 is fixed by this because cLocale was (incorrectly) lowercased,
which broke locale names like pt_BR to pt_br.
use netbuf;
use std::io::Read;
use std::io::Result;
use nom::IResult;
pub mod messages;
mod parser;
pub struct ProtocolDecoder {
buf: netbuf::Buf,
consumed: usize,
}
impl ProtocolDecoder {
pub fn new() -> ProtocolDecoder {
ProtocolDecoder {
buf: netbuf::Buf::new(),
consumed: 0,
}
}
pub fn read_from<R: Read>(&mut self, stream: &mut R) -> Result<usize> {
self.buf.read_from(stream)
}
pub fn extract_messages(&mut self) -> Vec<messages::HWProtocolMessage> {
let parse_result = parser::extract_messages(&self.buf[..]);
match parse_result {
IResult::Done(tail, msgs) => {
self.consumed = self.buf.len() - self.consumed - tail.len();
msgs
},
IResult::Incomplete(_) => unreachable!(),
IResult::Error(_) => unreachable!(),
}
}
pub fn sweep(&mut self) {
self.buf.consume(self.consumed);
self.consumed = 0;
}
}