normalizeSearchText function

String normalizeSearchText(
  1. String input
)

Fold case and Arabic presentation so search matches across scripts.

Strips tatweel and harakat, and maps alef / yeh variants to a common form.

Implementation

String normalizeSearchText(String input) {
  final buffer = StringBuffer();
  for (final unit in input.trim().codeUnits) {
    if (unit == 0x0640) continue; // tatweel
    if (unit >= 0x064B && unit <= 0x065F) continue; // harakat
    if (unit == 0x0670) continue; // superscript alef
    if (unit == 0x0622 || unit == 0x0623 || unit == 0x0625 || unit == 0x0671) {
      buffer.write('\u0627'); // آ أ إ ٱ → ا
      continue;
    }
    if (unit == 0x0649) {
      buffer.write('\u064A'); // ى → ي
      continue;
    }
    buffer.writeCharCode(unit);
  }
  return buffer.toString().toLowerCase();
}