Why does readln include the line terminator?
Daniel Keep
daniel.keep.lists at gmail.com
Tue Apr 14 20:02:23 PDT 2009
Andrei Alexandrescu wrote:
> Daniel Keep wrote:
>>
>> Andrei Alexandrescu wrote:
>>> ...
>>>
>>> Right now readln preserves the separator. The newer File.byLine
>>> eliminates it by default and offers to keep it by calling
>>> File.byLine(KeepTerminator.yes). The allowed terminators are one
>>> character or a string. See
>>>
>>> http://erdani.dreamhosters.com/d/web/phobos/std_stdio.html#byLine
>>>
>>> I consider such an API adequate but insufficient; we need to add to it.
>>>
>>>
>>> Andrei
>>
>> Why not:
>>
>> char[] line, sep;
>> line = File.byLine(); // discard sep
>> line = File.byLine(sep); // pass sep out
>>
>> The separator is likely to be more useful once extracted.
>
> And how about when sep is elaborate (e.g. regex)?
>
> Andrei
Whatever was matched. If we have a file containing:
"A.B,C"
And we split lines using /[.,]/, then this:
> char[] line, sep;
> line = File.byLine(sep);
> while( line != "" )
> {
> writefln(`line = "%s", sep = "%s"`, line, sep);
> line = File.byLine(sep);
> }
Would output this:
> line = "A", sep = "."
> line = "B", sep = ","
> line = "C", sep = ""
-- Daniel
More information about the Digitalmars-d
mailing list