findSplitBefore

Array-specialization of findSplitBefore with explicit needle-only predicate needlePred.

  1. auto findSplitBefore(inout(T)[] haystack, T needle)
  2. auto findSplitBefore(inout(T)[] haystack)
    findSplitBefore
    (
    alias needlePred
    T
    )
    (
    scope return inout(T)[] haystack
    )

Examples

char[] haystack;
auto r = haystack.findSplitBefore!(_ => _ == '_');
static assert(is(typeof(r.pre()) == char[]));
static assert(is(typeof(r.post()) == char[]));
assert(!r);
assert(!r.pre);
assert(!r.post);

auto f()() @safe pure nothrow { char[1] x = "_"; return x[].findSplitBefore!(_ => _ == ' '); }
static if (isDIP1000) static assert(!__traits(compiles, { auto _ = f(); }));
const(char)[] haystack;
auto r = haystack.findSplitBefore!(_ => _ == '_');
static assert(is(typeof(r.pre()) == const(char)[]));
static assert(is(typeof(r.post()) == const(char)[]));
assert(!r);
assert(!r.pre);
assert(!r.post);
const r = "a*b".findSplitBefore!(_ => _ == '*');
assert(r);
assert(r.pre == "a");
assert(r.post == "*b");
const r = "a*b".findSplitBefore!(_ => _ == '*' || _ == '+');
assert(r);
assert(r.pre == "a");
assert(r.post == "*b");
const r = "a+b".findSplitBefore!(_ => _ == '*' || _ == '+');
assert(r);
assert(r.pre == "a");
assert(r.post == "+b");
const r = "a*b".findSplitBefore!(_ => _ == '_');
assert(!r);
assert(r.pre == "a*b");
assert(r.post == "");

See Also

Meta