View source code
Display the source code in std/algorithm/searching.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Template std.algorithm.searching.skipOver
Skip over the initial portion of the first given range (haystack
) that matches
any of the additionally given ranges (needles
) fully, or
if no second range is given skip over the elements that fulfill pred.
Do nothing if there is no match.
template skipOver(alias pred)
;
Contained Functions
Name | Description |
---|---|
skipOver |
Parameters
Name | Description |
---|---|
pred | The predicate that determines whether elements from each respective
range match. Defaults to equality "a == b" . |
Example
import std .algorithm .comparison : equal;
auto s1 = "Hello world";
assert(!skipOver(s1, "Ha"));
writeln(s1); // "Hello world"
assert(skipOver(s1, "Hell") && s1 == "o world", s1);
string[] r1 = ["abc", "def", "hij"];
dstring[] r2 = ["abc"d];
assert(!skipOver!((a, b) => a .equal(b))(r1, ["def"d]), r1[0]);
writeln(r1); // ["abc", "def", "hij"]
assert(skipOver!((a, b) => a .equal(b))(r1, r2));
writeln(r1); // ["def", "hij"]
Example
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);
Example
Variadic skipOver
auto s = "Hello world";
assert(!skipOver(s, "hello", "HellO"));
writeln(s); // "Hello world"
// the range is skipped over the longest matching needle is skipped
assert(skipOver(s, "foo", "hell", "Hello "));
writeln(s); // "world"
Example
import std .algorithm .comparison : equal;
auto s1 = "Hello world";
assert(!skipOver(s1, 'a'));
writeln(s1); // "Hello world"
assert(skipOver(s1, 'H') && s1 == "ello world");
string[] r = ["abc", "def", "hij"];
dstring e = "abc"d;
assert(!skipOver!((a, b) => a .equal(b))(r, "def"d));
writeln(r); // ["abc", "def", "hij"]
assert(skipOver!((a, b) => a .equal(b))(r, e));
writeln(r); // ["def", "hij"]
auto s2 = "";
assert(!s2 .skipOver('a'));
Example
Partial instantiation
import std .ascii : isWhite;
import std .range .primitives : empty;
alias whitespaceSkiper = skipOver!isWhite;
auto s2 = "\t\tvalue";
auto s3 = "";
auto s4 = "\t\t\t";
assert(whitespaceSkiper(s2) && s2 == "value");
assert(!whitespaceSkiper(s2));
assert(whitespaceSkiper(s4) && s3 .empty);
Authors
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.