indexOf

Array-specialization of indexOf with default predicate.

TODO: Add optimized implementation for needles with length >= largeNeedleLength with no repeat of elements.

  1. ptrdiff_t indexOf(inout(T)[] haystack, const(T)[] needle)
  2. ptrdiff_t indexOf(inout(T)[] haystack, T needle)
    ptrdiff_t
    indexOf
    (
    T
    )
    (
    scope inout(T)[] haystack
    ,
    scope const T needle
    )
  3. bool startsWith(T[] haystack, T[] needle)
  4. bool startsWith(T[] haystack, T needle)

Examples

assert("_abc_abc_".indexOf("abc") == 1);
assert("__abc_".indexOf("abc") == 2);
assert("a".indexOf("a") == 0);
assert("abc".indexOf("abc") == 0);
assert("_".indexOf("a") == -1);
assert("_".indexOf("__") == -1);
assert("__".indexOf("a") == -1);
assert("_".indexOf('a') == -1);
assert("a".indexOf('a') == 0);
assert("_a".indexOf('a') == 1);
assert("__a".indexOf('a') == 2);

Meta