findSkip

Array-specialization of findSkip with default predicate.

  1. auto findSkip(inout(T)[] haystack, T[] needle)
  2. auto findSkip(inout(T)[] haystack, T needle)
    @trusted
    findSkip
    (
    T
    )
    (
    scope ref inout(T)[] haystack
    ,
    scope const T needle
    )
  3. bool startsWith(T[] haystack, T[] needle)
  4. bool startsWith(T[] haystack, T needle)

Examples

const auto x = "abc";
{
	string y = x;
	const bool ok = y.findSkip("_");
	assert(!ok);
	assert(y is x);
}
{
	string y = x;
	const bool ok = y.findSkip("a");
	assert(ok);
	assert(y == x[1 .. $]);
}
{
	string y = x;
	const bool ok = y.findSkip("c");
	assert(ok);
	assert(y is x[$ .. $]);
}
version (unittest) {
	static char[] f()() @safe pure nothrow { char[1] x = "_"; return x[].findSkip(" "); }
	static if (hasPreviewDIP1000) static assert(!__traits(compiles, { auto _ = f(); }));
}
const auto x = "abc";
{
	string y = x;
	const bool ok = y.findSkip('_');
	assert(!ok);
	assert(y is x);
}
{
	string y = x;
	const bool ok = y.findSkip('a');
	assert(ok);
	assert(y == x[1 .. $]);
}
{
	string y = x;
	const bool ok = y.findSkip('c');
	assert(ok);
	assert(y is x[$ .. $]);
}
version (unittest) {
	static char[] f()() @safe pure nothrow { char[1] x = "_"; return x[].findSkip(' '); }
	static if (hasPreviewDIP1000) static assert(!__traits(compiles, { auto _ = f(); }));
}

Meta