findSplit

Undocumented in source.
template findSplit(needles...)
@trusted
findSplit
(
Haystack
)
(
const scope return Haystack haystack
)
if (
is(typeof(Haystack.init[0 .. 0])) &&
is(typeof(Haystack.init[0]) : char)
&&
isASCII!(needles[0])
)
if (
needles.length == 1 &&
isExpressions!needles
)

Members

Functions

findSplit
auto findSplit(Haystack haystack)
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

const r = "a*b".findSplit!('*');
assert(r);

assert(r[0] == "a");
assert(r.pre == "a");

assert(r[1] == "*");
assert(r.separator == "*");

assert(r[2] == "b");
assert(r.post == "b");
auto r = "a+b*c".findSplitAmong!('+', '-');

static assert(r.sizeof == 24);
static assert(is(typeof(r.pre) == string));
static assert(is(typeof(r.separator) == string));
static assert(is(typeof(r.post) == string));

assert(r);

assert(r[0] == "a");
assert(r.pre == "a");

assert(r[1] == "+");
assert(r.separator == "+");

assert(r[2] == "b*c");
assert(r.post == "b*c");
const r = "a+b*c".findSplitAmong!('-', '*');
assert(r);
assert(r.pre == "a+b");
assert(r.separator == "*");
assert(r.post == "c");
const r = "a*".findSplitAmong!('*');

assert(r);

assert(r[0] == "a");
assert(r.pre == "a");

assert(r[1] == "*");
assert(r.separator == "*");

assert(r[2] == "");
assert(r.post == "");
const r = "*b".findSplitAmong!('*');

assert(r);

assert(r[0] == "");
assert(r.pre == "");

assert(r[1] == "*");
assert(r.separator == "*");

assert(r[2] == "b");
assert(r.post == "b");
const r = "*".findSplitAmong!('*');

assert(r);

assert(r[0] == "");
assert(r.pre == "");

assert(r[1] == "*");
assert(r.separator == "*");

assert(r[2] == "");
assert(r.post == "");
static immutable separator_char = '/';

immutable r = "a+b*c".findSplitAmong!(separator_char);

static assert(r.sizeof == 24);
static assert(is(typeof(r.pre) == immutable string));
static assert(is(typeof(r.separator) == immutable string));
static assert(is(typeof(r.post) == immutable string));

assert(!r);

assert(r.pre == "a+b*c");
assert(r[0] == "a+b*c");
assert(r.separator == []);
assert(r[1] == []);
assert(r.post == []);
assert(r[2] == []);

Meta