isProbablyArabicInLine static method

bool isProbablyArabicInLine(
  1. String s
)

Implementation

static bool isProbablyArabicInLine(String s) {
  if (s.length == 0) return false;
  // print("string:" + s);
  List<String> words = s.trim().split(' ');
  List<ArabicIndex> arabicIndex = [];
  int firstIndex = -1;
  int lastIndex = -1;

  words.forEach((word) {
    for (int i = 0; i < word.length; i++) {
      // print(i);
      // print(word);
      int c = word.codeUnitAt(i);
      if (c >= 0x0600 && c <= 0x06E0) {
        if (firstIndex == -1) {
          firstIndex = i;
        } else {
          lastIndex = i;
        }
        // arabicIndex.add(i);
      } else {
        // not arabic.
        if (firstIndex != -1 && lastIndex != -1)
          arabicIndex.add(ArabicIndex(firstIndex, lastIndex,
              words.sublist(firstIndex, lastIndex).join(' ')));
        firstIndex = -1;
        lastIndex = -1;
      }
      // i += s.characters.length;
    }
  });

  if (arabicIndex.length > 0) {
    print(arabicIndex);
  }

  return false;
}