hasExcessiveRepeatedText method

bool hasExcessiveRepeatedText()

Check for excessive repeated text patterns

Implementation

bool hasExcessiveRepeatedText() {
  // Check for same character repeated more than 4 times
  if (RegExp(r'(.)\1{4,}').hasMatch(this)) return true;

  // Check for same word repeated more than 2 times
  final List<String> words = split(RegExp(r'\s+'));
  for (final String word in words) {
    if (word.length > 2) {
      final int wordCount = words
          .where((String w) => w.toLowerCase() == word.toLowerCase())
          .length;
      if (wordCount > 2) return true;
    }
  }

  return false;
}