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)
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.
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 ..
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')
{