File() vs. std.cstream.din

Gerome Fournier Gerome_member at pathlink.com
Sat Apr 22 08:01:40 PDT 2006


In article <ops8bt9xwe23k2f5 at nrage.netwin.co.nz>, Regan Heath says...
>
>My guess is that it is related to when eof is flagged. In the File case it  
>reads the last line and flags eof, in the case of din it has to read past  
>the end to flag eof.

>If you modify the code to be:
>
>void dump_stream(Stream s)
>{
>	while (!s.eof()) {
>		char[] line = s.readLine();
>		if (line !is null) printf("Line: %.*s\n", line);
>	}
>}

Thanks for your comment. You're right telling that concerning din, looks like
it's looking past the end of file to flag eof. Sounds like a kind of bug to me,
as I would expect the same behaviour between a file based stream (a seekable
stream), and a din based stream (a non seekable stream).

>If you modify the code to be:
>
>void dump_stream(Stream s)
>{
>	while (!s.eof()) {
>		char[] line = s.readLine();
>		if (line !is null) printf("Line: %.*s\n", line);
>	}
>}

Unfortunatly this change doesn't work when you have empty lines in your file, 
as they're skipped. Reading a line containing a single '\n' will give a null 
value to variable line through the call to readLine.

I've even noticed that calling readLine on a non seekable Stream (like
std.cstream.din) on a file using the dos '\r\n' end of line sequence,
will stop when '\r' is seen. And a second call to readLine will stop on
the following '\n'. The sequence '\r\n' is not eaten as a whole end of line
sequence, like it's done for a seekable stream.





More information about the Digitalmars-d mailing list