Function std.algorithm.searching.findSplit
These functions find the first occurrence of in needle and then split haystack as follows.
haystack
returns a tuple findSplitresult containing three
ranges. result[0] is the portion of before haystack, needleresult[1] is the portion of that matches
haystack, and needleresult[2] is the portion of after
the match. If haystack was not found, needleresult[0]
comprehends entirely and haystackresult[1] and result[2]
are empty.
returns a tuple findSplitBeforeresult containing two
ranges. result[0] is the portion of before haystack, and needleresult[1] is the balance of starting
with the match. If haystack was not found, needleresult[0]
comprehends entirely and haystackresult[1] is empty.
returns a tuple findSplitAfterresult containing two ranges.
result[0] is the portion of up to and including the
match, and haystackresult[1] is the balance of starting
after the match. If haystack was not found, needleresult[0] is empty
and result[1] is .
haystack
In all cases, the concatenation of the returned ranges spans the
entire .
haystack
If is a random-access range, haystackall three components of the
tuple have the same type as . Otherwise, haystack
must be a forward range and the type of haystackresult[0] and result[1] is the same as std.range.takeExactly.
Prototype
auto findSplit(alias pred, R1, R2)( R1 haystack, R2 needle ) if (isForwardRange!R1 && isForwardRange!R2);
Example
auto a = "Carl Sagan Memorial Station"; auto r = findSplit(a, "Velikovsky"); assert(r[0] == a); assert(r[1].empty); assert(r[2].empty); r = findSplit(a, " "); assert(r[0] == "Carl"); assert(r[1] == " "); assert(r[2] == "Sagan Memorial Station"); auto r1 = findSplitBefore(a, "Sagan"); assert(r1[0] == "Carl ", r1[0]); assert(r1[1] == "Sagan Memorial Station"); auto r2 = findSplitAfter(a, "Sagan"); assert(r2[0] == "Carl Sagan"); assert(r2[1] == " Memorial Station");