moveWordBackwardFromReader function
int
moveWordBackwardFromReader(
- int length,
- int offset, {
- required GraphemePredicate isWord,
- required GraphemeReader graphemeAt,
Implementation
int moveWordBackwardFromReader(
int length,
int offset, {
required GraphemePredicate isWord,
required GraphemeReader graphemeAt,
}) {
if (offset <= 0 || length <= 0) {
return 0;
}
var position = offset - 1;
while (position > 0) {
final grapheme = graphemeAt(position);
if (grapheme != null && isWord(grapheme)) {
break;
}
position--;
}
while (position > 0) {
final grapheme = graphemeAt(position - 1);
if (grapheme == null || !isWord(grapheme)) {
break;
}
position--;
}
return position.clamp(0, length);
}