Re: std.range.byLine

2014-09-12 Thread Nordlöw
On Thursday, 11 September 2014 at 22:39:40 UTC, H. S. Teoh via Digitalmars-d-learn Why not just use std.regex? foreach (line; myInput.split(regex(`\n|\r\n|\r`))) { ... } T I'll try the lazy variant of std.regex foreach (line;

Re: std.range.byLine

2014-09-12 Thread Nordlöw
On Thursday, 11 September 2014 at 22:39:40 UTC, H. S. Teoh via Digitalmars-d-learn wrote: foreach (line; myInput.split(regex(`\n|\r\n|\r`))) Shouldn't you use foreach (line; myInput.split(regex(\n|\r\n|\r))) here?

Re: std.range.byLine

2014-09-12 Thread monarch_dodra via Digitalmars-d-learn
On Friday, 12 September 2014 at 13:25:22 UTC, Nordlöw wrote: On Thursday, 11 September 2014 at 22:39:40 UTC, H. S. Teoh via Digitalmars-d-learn wrote: foreach (line; myInput.split(regex(`\n|\r\n|\r`))) Shouldn't you use foreach (line; myInput.split(regex(\n|\r\n|\r))) here?

Re: std.range.byLine

2014-09-12 Thread Nordlöw
On Friday, 12 September 2014 at 14:16:07 UTC, monarch_dodra wrote: Probably not, as (AFAIK) the splitter engine *itself* will *also* escape the passed in characters. IE: It literally needs the characters '\' and 'n'. I ended up with this.

Re: std.range.byLine

2014-09-11 Thread monarch_dodra via Digitalmars-d-learn
On Wednesday, 10 September 2014 at 23:01:44 UTC, Nordlöw wrote: On Wednesday, 10 September 2014 at 22:45:08 UTC, Nordlöw wrote: auto byLine(Range)(Range input) if (isForwardRange!Range) { import std.algorithm: splitter; import std.ascii: newline; static if (newline.length == 1) {

Re: std.range.byLine

2014-09-11 Thread Nordlöw
On Thursday, 11 September 2014 at 10:19:17 UTC, monarch_dodra wrote: Well, the issue is that this isn't very portable for *reading*, as even on linux, you may read files with \r\n line endings (It's standard for csv files, for example), or read \n terminated files on windows. The issue is that

Re: std.range.byLine

2014-09-11 Thread monarch_dodra via Digitalmars-d-learn
On Thursday, 11 September 2014 at 20:03:26 UTC, Nordlöw wrote: On Thursday, 11 September 2014 at 10:19:17 UTC, monarch_dodra wrote: Well, the issue is that this isn't very portable for *reading*, as even on linux, you may read files with \r\n line endings (It's standard for csv files, for

Re: std.range.byLine

2014-09-11 Thread Nordlöw
On Thursday, 11 September 2014 at 21:29:16 UTC, monarch_dodra wrote: Bummer... Anyway, it shouldn't be too hard to express this in a new range.

Re: std.range.byLine

2014-09-11 Thread Nordlöw
On Thursday, 11 September 2014 at 21:29:16 UTC, monarch_dodra wrote: Hum... no, those are the correct splitting elements. However, I don't think that would actually work, as find will privilege the first whole element to match as a hit, so \r\n never be hit (rather, it will be hit twice, in

Re: std.range.byLine

2014-09-11 Thread Nordlöw
On Thursday, 11 September 2014 at 21:54:39 UTC, Nordlöw wrote: Anyway, it shouldn't be too hard to express this in a new range. I guess what we need is a variant of splitter with a more greedy alias template parameter that will digest two or one bytes.

Re: std.range.byLine

2014-09-11 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Sep 11, 2014 at 10:31:33PM +, Nordlöw via Digitalmars-d-learn wrote: On Thursday, 11 September 2014 at 21:54:39 UTC, Nordlöw wrote: Anyway, it shouldn't be too hard to express this in a new range. I guess what we need is a variant of splitter with a more greedy alias template

std.range.byLine

2014-09-10 Thread Nordlöw
I'm missing a range variant of byLine that can operate on strings instead of just File. This is such a common feature so I believe it should have its place in std.range. My suggestion is to define this using splitter!(std.uni.isNewline) but I'm missing std.uni.isNewline. I'm guessing the

Re: std.range.byLine

2014-09-10 Thread Ali Çehreli via Digitalmars-d-learn
On 09/10/2014 02:06 PM, Nordlöw wrote: I'm missing a range variant of byLine that can operate on strings instead of just File. This is such a common feature so I believe it should have its place in std.range. My suggestion is to define this using splitter!(std.uni.isNewline) but I'm missing

Re: std.range.byLine

2014-09-10 Thread Nordlöw
On Wednesday, 10 September 2014 at 22:29:55 UTC, Ali Çehreli wrote: assert(foo\nbar\n .splitter(newline) .filter!(a = !a.empty) .equal([ foo, bar ])); } Ali Ok, great. So I got. auto byLine(Range)(Range input) if (isForwardRange!Range) { import

Re: std.range.byLine

2014-09-10 Thread Nordlöw
On Wednesday, 10 September 2014 at 22:45:08 UTC, Nordlöw wrote: auto byLine(Range)(Range input) if (isForwardRange!Range) { import std.algorithm: splitter; import std.ascii: newline; static if (newline.length == 1) { return input.splitter(newline.front); } else