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 that matches the second range, or if no second range is given skip over the elements that fullfil pred. Do nothing if there is no match.

template skipOver(alias pred) ;

Contained Functions

NameDescription
skipOver r1 = The forward range to move forward. r2 = The input range representing the initial segment of r1 to skip over. e = The element to match.

Parameters

NameDescription
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");

string[]  r1 = ["abc", "def", "hij"];
dstring[] r2 = ["abc"d];
assert(!skipOver!((a, b) => a.equal(b))(r1, ["def"d]));
writeln(r1); // ["abc", "def", "hij"]
assert(skipOver!((a, b) => a.equal(b))(r1, r2));
writeln(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);

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

Andrei Alexandrescu

License

Boost License 1.0.