add method

int add(
  1. String str, {
  2. bool ignorePunctuation = false,
})

Add another string to be processed, returns the counts. ignorePunctuation facilitates checking words that include symbols.

Implementation

int add(String str, {bool ignorePunctuation = false}) {
  if (str.isEmpty) {
    _inWord = false;
    return _count;
  }

  _count += wordCount(str, inWord: _inWord);

  final lastChar = str[str.length - 1];
  var punctuationContinue = !ignorePunctuation && !lastChar.isPunctuation;
  if (lastChar.isChar && !lastChar.isWhiteSpace && punctuationContinue) {
    _inWord = true;
  } else {
    _inWord = false;
  }
  return _count;
}