search function

List<int> search(
  1. List<int> haystack,
  2. List<int> needle
)

Implementation

List<int> search(List<int> haystack, List<int> needle) {
  final needleTable = _getNeedleTable(needle);
  var current = 0;
  final List<int> positions = [];
  while (current + needle.length < haystack.length) {
    final foundPos = _searchOne(haystack.sublist(current), needle, needleTable);
    if (foundPos == null) {
      return positions;
    } else {
      positions.add(foundPos);
      current += foundPos + needle.length + 1;
    }
  }
  return positions;
}