The predicate for comparing each element with the separator, defaulting to "a == b".
The input range to be split.
The forward range to be treated as the separator between segments of r to be split.
Constraints: The predicate pred needs to accept an element of r and an element of s.
An input range of the subranges of elements between separators. If r is a forward range or bidirectional range, the returned range will be likewise.
1 import std.algorithm.comparison : equal; 2 3 assert(equal(splitter("hello world", " "), [ "hello", "world" ])); 4 int[] a = [ 1, 2, 0, 0, 3, 0, 4, 5, 0 ]; 5 int[][] w = [ [1, 2], [3, 0, 4, 5, 0] ]; 6 assert(equal(splitter(a, [0, 0]), w)); 7 a = [ 0, 0 ]; 8 assert(equal(splitter(a, [0, 0]), [ (int[]).init, (int[]).init ])); 9 a = [ 0, 0, 1 ]; 10 assert(equal(splitter(a, [0, 0]), [ [], [1] ]));
std.regex._splitter for a version that splits using a regular expression defined separator.
Similar to the previous overload of splitter, except this one uses another range as a separator. This can be used with any narrow string type or sliceable range type, but is most popular with string types. The predicate is passed to std.functional.binaryFun, and can either accept a string, or any callable that can be executed via pred(r.front, s.front).
Two adjacent separators are considered to surround an empty element in the split range. Use filter!(a => !a.empty) on the result to compress empty elements.