getSentences method

List<String> getSentences(
  1. String text
)

Returns a list of sentences for a block of text.

Implementation

List<String> getSentences(String text) {
  RegExp regex = RegExp(r'.{1,}?([。.」??!!]+|\n)');

  Iterable<Match> matches = regex.allMatches(text);

  if (matches.isEmpty) {
    return [text];
  }

  List<String> sentences = regex.allMatchesWithSep(text);

  return sentences;
}