split method

List<TextChunk> split(
  1. String text
)

Splits text; whitespace-only input gives no chunks.

Implementation

List<TextChunk> split(String text) {
  final n = text.length;
  final chunks = <TextChunk>[];
  var start = _skipSpace(text, 0);
  while (start < n) {
    final end = start + chunkSize >= n ? n : _cut(text, start);
    var e = end;
    while (e > start && _isSpace(text.codeUnitAt(e - 1))) {
      e--;
    }
    if (e > start) {
      chunks.add(
        TextChunk(chunks.length, text.substring(start, e), start, e),
      );
    }
    if (end >= n) break;
    var next = end - overlap;
    next = next <= start ? end : _wordStart(text, next, end);
    start = _skipSpace(text, next);
  }
  return chunks;
}