nextWordRange function

({int end, int start})? nextWordRange(
  1. List<String> graphemes,
  2. int offset, {
  3. 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);
}