searchUint8List function

int searchUint8List(
  1. Uint8List haystack,
  2. Uint8List needle
)

Returns the position of the first match of needle in haystack or -1.

Implementation

int searchUint8List(Uint8List haystack, Uint8List needle) {
  if (needle.isEmpty) return -1;
  for (int i = 0; i < haystack.length - needle.length + 1; i++) {
    int j = 0;
    while (j < needle.length && haystack[i + j] == needle[j]) {
      j++;
    }
    if (j == needle.length) return i;
  }
  return -1;
}