findMatches function
Start offsets of every case-insensitive, non-overlapping match of needle (already lowercase) in text.
Implementation
List<int> findMatches(String text, String needle) {
if (needle.isEmpty) return const [];
final haystack = text.toLowerCase();
final starts = <int>[];
var from = 0;
while (true) {
final index = haystack.indexOf(needle, from);
if (index < 0) return starts;
starts.add(index);
from = index + needle.length;
}
}