From 3c96452e66e212515aab0825f33043f5e1b31902 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 30 May 2019 10:51:55 -0400 Subject: [PATCH] lib/core/stream: LineIterator use CachedIterator The logic behind `is_ok` was broken and caused inconsitent results. Signed-off-by: Jean Privat --- lib/core/stream.nit | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/lib/core/stream.nit b/lib/core/stream.nit index 152c294..b0486ef 100644 --- a/lib/core/stream.nit +++ b/lib/core/stream.nit @@ -484,37 +484,18 @@ end # Iterator returned by `Reader::each_line`. # See the aforementioned method for details. class LineIterator - super Iterator[String] + super CachedIterator[String] # The original stream var stream: Reader - redef fun is_ok + redef fun next_item do - var res = not stream.eof - if not res and close_on_finish then stream.close - return res - end - - redef fun item - do - var line = self.line - if line == null then - line = stream.read_line + if stream.eof then + if close_on_finish then stream.close + return null end - self.line = line - return line - end - - # The last line read (cache) - private var line: nullable String = null - - redef fun next - do - # force the read - if line == null then item - # drop the line - line = null + return stream.read_line end # Close the stream when the stream is at the EOF. -- 1.7.9.5