findSplitBefore

Array-specialization of findSplitBefore with default predicate.

  1. auto findSplitBefore(inout(T)[] haystack, T needle)
    findSplitBefore
    (
    T
    )
    (
    scope return inout(T)[] haystack
    ,
    scope const T needle
    )
  2. auto findSplitBefore(inout(T)[] haystack)
  3. bool startsWith(T[] haystack, T[] needle)
  4. bool startsWith(T[] haystack, T needle)

Examples

char[] haystack;
auto r = haystack.findSplitBefore('_');
static assert(is(typeof(r.pre()) == typeof(haystack)));
static assert(is(typeof(r.post()) == typeof(haystack)));
assert(!r);
assert(!r.pre);
assert(!r.post);
version (unittest) {
	static auto f()() @safe pure nothrow { char[1] x = "_"; return x[].findSplitBefore(' '); }
	static if (hasPreviewDIP1000) static assert(!__traits(compiles, { auto _ = f(); }));
}
const(char)[] haystack;
auto r = haystack.findSplitBefore('_');
static assert(is(typeof(r.pre()) == typeof(haystack)));
static assert(is(typeof(r.post()) == typeof(haystack)));
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*b");
assert(r.post == "");

See Also

Meta