cleaningText method

void cleaningText()

Cleaning text to detect

(eliminate URL, e-mail address and Latin sentence if it is not written in Latin alphabet).

Implementation

void cleaningText() {
  int latinCount = 0;
  int nonLatinCount = 0;
  for (int codeUnit in text.codeUnits) {
    String ch = String.fromCharCode(codeUnit);
    if ('A'.compareTo(ch) <= 0 && ch.compareTo('z') <= 0) {
      latinCount++;
    } else if (ch.compareTo('\u0300') >= 0 &&
        unicodeBlock(ch) != UnicodeBlock.unicodeLatinExtendedAdditional) {
      nonLatinCount++;
    }
  }

  if (latinCount * 2 < nonLatinCount) {
    String textWithoutLatin = '';
    for (int codeUnit in text.codeUnits) {
      String ch = String.fromCharCode(codeUnit);
      if (ch.compareTo('A') < 0 || ch.compareTo('z') > 0) {
        textWithoutLatin += ch;
      }
    }
    text = textWithoutLatin;
  }
}