Why does readln include the line terminator?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Apr 14 21:21:48 PDT 2009


Daniel Keep wrote:
> 
> 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

Where did you specify the separator in the call to byLine?

Andrei



More information about the Digitalmars-d mailing list