Merge pull request #5543 from RazvanN7/Issue_17525

Fix Issue 17525 - std.algorithm.searching.skipOver should have a single argument with pred version
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
This commit is contained in:
The Dlang Bot 2017-07-07 08:35:05 +02:00 committed by GitHub
commit 37d15a89c5

View file

@ -3907,7 +3907,8 @@ if (isInputRange!Range && !isInfinite!Range &&
/**
Skip over the initial portion of the first given range that matches the second
range, or do nothing if there is no match.
range, or if no second range is given skip over the elements that fullfil pred.
Do nothing if there is no match.
Params:
pred = The predicate that determines whether elements from each respective
@ -3918,9 +3919,9 @@ Params:
representing the initial segment of $(D r1) to skip over.
Returns:
true if the initial segment of $(D r1) matches $(D r2), and $(D r1) has been
advanced to the point past this segment; otherwise false, and $(D r1) is left
in its original position.
true if the initial segment of $(D r1) matches $(D r2) or $(D pred) evaluates to true,
and $(D r1) has been advanced to the point past this segment; otherwise false, and
$(D r1) is left in its original position.
*/
bool skipOver(R1, R2)(ref R1 r1, R2 r2)
if (isForwardRange!R1 && isInputRange!R2
@ -3966,6 +3967,20 @@ if (is(typeof(binaryFun!pred(r1.front, r2.front))) &&
return r2.empty;
}
/// Ditto
bool skipOver(alias pred, R)(ref R r1)
if (isForwardRange!R &&
ifTestable!(typeof(r1.front), unaryFun!pred))
{
if (r1.empty || !unaryFun!pred(r1.front))
return false;
do
r1.popFront();
while (!r1.empty && unaryFun!pred(r1.front));
return true;
}
///
@safe unittest
{
@ -3982,6 +3997,16 @@ if (is(typeof(binaryFun!pred(r1.front, r2.front))) &&
assert(r1 == ["abc", "def", "hij"]);
assert(skipOver!((a, b) => a.equal(b))(r1, r2));
assert(r1 == ["def", "hij"]);
import std.ascii : isWhite;
import std.range.primitives : empty;
auto s2 = "\t\tvalue";
auto s3 = "";
auto s4 = "\t\t\t";
assert(s2.skipOver!isWhite && s2 == "value");
assert(!s3.skipOver!isWhite);
assert(s4.skipOver!isWhite && s3.empty);
}
/**