Adds proper detection of NTriples end of file

pull/10/head
Tpt 6 years ago
parent 47d5f677cb
commit 04dd67c493
  1. 23
      src/rio/ntriples/mod.rs

@ -25,18 +25,17 @@ impl<R: Read> Iterator for NTriplesIterator<R> {
type Item = Result<Triple>; type Item = Result<Triple>;
fn next(&mut self) -> Option<Result<Triple>> { fn next(&mut self) -> Option<Result<Triple>> {
match self.reader.read_line(&mut self.buffer) { if let Err(error) = self.reader.read_line(&mut self.buffer) {
Ok(line_count) => if line_count == 0 { return Some(Err(error.into()));
None }
} else { if self.buffer.is_empty() {
let result = grammar::triple(&self.buffer, &mut self.bnodes_map); return None; //End of file
self.buffer.clear(); }
match result { let result = grammar::triple(&self.buffer, &mut self.bnodes_map);
Ok(Some(triple)) => Some(Ok(triple)), self.buffer.clear();
Ok(None) => self.next(), match result {
Err(error) => Some(Err(error.into())), Ok(Some(triple)) => Some(Ok(triple)),
} Ok(None) => self.next(),
},
Err(error) => Some(Err(error.into())), Err(error) => Some(Err(error.into())),
} }
} }

Loading…
Cancel
Save