Why does std.string.splitLines return an array?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Mon Oct 22 03:51:36 PDT 2012
On 10/22/12 1:05 AM, Chad J wrote:
> On 10/21/2012 06:35 PM, Jonathan M Davis wrote:
>> On Sun, 2012-10-21 at 18:00 -0400, Chad J wrote:
>>> std.string.splitLines returns an array, which is pretty grody. Why not
>>> return a lazily-evaluated range struct so that we can avoid allocations
>>> on this simple but common operation?
>>
>> If you want a lazy range, then use std.algorithm.splitter. std.string
>> operates on and returns strings, not general ranges.
>>
>> - Jonathan M Davis
>>
>
> std.algorithm.splitter is simply not acceptable for this. It doesn't
> have this kind of logic:
>
> bool matchLineEnd( string text, size_t pos )
> {
> if ( pos+1 < text.length
> && text[pos] == '\r'
> && text[pos+1] == '\n' )
> return true;
> else if ( pos < text.length
> && (text[pos] == '\r' || text[pos] == '\n') )
> return true;
> else
> return false;
> }
Agreed. We should add splitter() accepting only one argument of some
string type. It would use the line splitting logic above.
Could you please adapt your code to do this and package it in a pull
request? Thanks!
Andrei
More information about the Digitalmars-d
mailing list