isShaddahToken static method

bool isShaddahToken(
  1. String tok
)

Determines if a token represents an acoustic Shaddah (doubled consonant).

Implementation

static bool isShaddahToken(String tok) {
  if (tok.length < 2) return false;
  final int c0 = tok.codeUnitAt(0);
  final int c1 = tok.codeUnitAt(1);
  if (c0 != c1) return false;
  // Cannot be Alif (اا is Madd)
  if (c0 == 0x0627) return false;
  // Bare unvoweled وو or يي (length 2 without harakah) could be Madd.
  // But if it has harakah (e.g. ييَ as in "إياك", or ووَ as in "توابا"), it is 100% Shaddah!
  if ((c0 == 0x0648 || c0 == 0x064A) && tok.length == 2) {
    return false;
  }
  return c0 >= 0x0621 && c0 <= 0x064A;
}