nextWordRange function
({int end, int start})?
nextWordRange(
- List<
String> graphemes, - int offset, {
- required GraphemePredicate isWord,
Implementation
({int start, int end})? nextWordRange(
List<String> graphemes,
int offset, {
required GraphemePredicate isWord,
}) {
if (graphemes.isEmpty) {
return null;
}
var position = offset.clamp(0, graphemes.length);
while (position < graphemes.length && !isWord(graphemes[position])) {
position++;
}
if (position >= graphemes.length) {
return null;
}
var end = position;
while (end < graphemes.length && isWord(graphemes[end])) {
end++;
}
return (start: position, end: end);
}