Fix Issue 18796 - Made substitute with multiple range elements correctly recognize empty base ranges

This commit is contained in:
dukc 2018-11-05 22:46:35 +02:00 committed by Sebastian Wilzbach
parent 84fe94c00e
commit d95bc60dad

View file

@ -5518,10 +5518,13 @@ if (isInputRange!R && Substs.length >= 2 && !is(CommonType!(Substs) == void))
this(R haystack, Ins needles)
{
hasHit = !haystack.empty;
this.rest = haystack.drop(0);
this.needles = needles;
popFront;
if (!haystack.empty)
{
hasHit = true;
popFront;
}
static if (hasNested!(typeof(skip)))
skip = rest.take(0);
}
@ -5936,6 +5939,25 @@ if (isInputRange!R && Substs.length >= 2 && !is(CommonType!(Substs) == void))
assert([1, 2, 3, 4].substitute([3, 4], [7, 8]).equal([1, 2, 7, 8]));
}
// tests recognizing empty base ranges
nothrow pure @safe unittest
{
import std.utf : byCodeUnit;
import std.algorithm.comparison : equal;
assert("".byCodeUnit.substitute('4', 'A').empty);
assert("".byCodeUnit.substitute('0', 'O', '5', 'S', '1', 'l').empty);
assert("".byCodeUnit.substitute("PKM".byCodeUnit, "PoKeMon".byCodeUnit).empty);
assert("".byCodeUnit.substitute
( "ding".byCodeUnit,
"dong".byCodeUnit,
"click".byCodeUnit,
"clack".byCodeUnit,
"ping".byCodeUnit,
"latency".byCodeUnit
).empty);
}
// sum
/**
Sums elements of `r`, which must be a finite