I'd prefer the behaviour that would add a newline to files that don't have any terminating newline on the final line. That's a marginal case, and all reasonable programs should interpret the files in the same way. The iterator is also free to discard information about whether \n or \r\n was used in the input.
And if that's not acceptable, I'd prefer an iterator that emits lines *including* any newline characters. I.e.
"a\nb" --> "a\n", "b" "a\nb\n" --> "a\n", "b\n" "a\r\nb\n" --> "a\r\n", "b\n"
That seems to be the only reasonable behaviour, assuming that you want to keep detailed information about line endings around.
I find both of these alternatives a lot better, clearer and less obscure than the behaviour Peter prefers.
/ Niels Möller ()
Previous text:
2002-12-31 16:00: Subject: Re: stdin->line_iterator
On Tue, Dec 31, 2002 at 03:50:04PM +0100, Niels Möller () @ Pike (-) developers forum wrote:
foreach(Stdio.stdin.line_iterator();; string x) write("%s\n", process_line(x)); must do the right thing.
The iterator you're arguing for simply doesn't do that.
but which one will?
if there is no \n at the very end, you get two options: either the last line will be dropped, which is bad, or your code above will add an extra \n at the end, which is not the right thing either.
greetings, martin.
interested in doing pike programming, sTeam/caudium/pike/roxen training, sTeam/caudium/roxen and/or unix system administration anywhere in the world. -- pike programmer working in europe csl-gmbh.net open-steam.org (www.archlab|(www|db).hb2).tuwien.ac.at unix bahai.or.at iaeste.(tuwien.ac|or).at systemadministrator (stuts|black.linux-m68k).org is.(schon.org|root.at) Martin Bähr http://www.iaeste.or.at/~mbaehr/
/ Brevbäraren