mirror of
https://github.com/dlang/phobos.git
synced 2025-05-04 17:11:26 +03:00
Fix Issue 18796 - Made substitute with multiple range elements correctly recognize empty base ranges
This commit is contained in:
parent
84fe94c00e
commit
d95bc60dad
1 changed files with 24 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue