Skip to content

Commit 2556323

Browse files
committed
Make byline ctfe-able on string arrays
1 parent 0d58aa0 commit 2556323

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

source/iopipe/textpipe.d

+30
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,20 @@ byline_outer_1:
341341
immutable t = delimElems[0];
342342
static if(isDynamicArray!(WindowType!(Chain)))
343343
{
344+
if(__ctfe)
345+
{
346+
// don't use pointer tricks or memchr
347+
while(newChecked < w.length)
348+
{
349+
if(w[newChecked++] == t)
350+
{
351+
// found it.
352+
endsWithDelim = true;
353+
break byline_outer_1;
354+
}
355+
}
356+
continue;
357+
}
344358
auto p = w.ptr + newChecked;
345359
static if(CodeUnitType.sizeof == 1)
346360
{
@@ -1088,3 +1102,19 @@ auto ref runEncoded(alias func, Chain, Args...)(Chain c, auto ref Args args)
10881102
}
10891103

10901104
// TODO: need unit tests here.
1105+
//
1106+
1107+
@safe nothrow unittest
1108+
{
1109+
// try running byline range with a string in CTFE
1110+
import std.range : walkLength;
1111+
static void testit(Char)()
1112+
{
1113+
enum immutable(Char)[] str = "hello\nworld\nthis\nis\na\ntest";
1114+
static assert(str.byLineRange.walkLength == 6);
1115+
}
1116+
1117+
testit!char();
1118+
testit!wchar();
1119+
testit!dchar();
1120+
}

0 commit comments

Comments
 (0)