[OT] Is this more readable, or just way too verbose?

2010-08-09 Thread simendsjo
I took splitlines from std.string, which is a simple, short method. S[] splitlines(S)(S s) { size_t istart; auto result = Appender!(S[])(); foreach (i; 0 .. s.length) { immutable c = s[i]; if (c == '\r' || c == '\n') { result.put(s[istart .. i]

Re: [OT] Is this more readable, or just way too verbose?

2010-08-09 Thread Lutger
simendsjo wrote: > I took splitlines from std.string, which is a simple, short method. > > S[] splitlines(S)(S s) > { > size_t istart; > auto result = Appender!(S[])(); > > foreach (i; 0 .. s.length) > { > immutable c = s[i]; > if (c == '\r' || c == '\n') >

Re: [OT] Is this more readable, or just way too verbose?

2010-08-10 Thread simendsjo
Lutger wrote: simendsjo wrote: (...) The CR and LF constants are a bit too much, probably because they don't really abstract over the literals which I can actually parse faster. The isCR and isLF are nice however. Taking it a step further: bool canSplit = inPattern(c,"\r\n"); if (canSplit

Re: [OT] Is this more readable, or just way too verbose?

2010-08-10 Thread Lutger
simendsjo wrote: > Lutger wrote: ... > I didn't increase the if nesting though. I count 2 nested if-statements inside of the foreach loop in the original, you have 3 nested if-statements. > Something like this then? Looks good to me, yes.