toLatinDigits function

String toLatinDigits(
  1. String input
)

Replaces Persian (۰ to ۹) and Arabic-Indic (٠ to ٩) digits in input with the ASCII digits 0 to 9.

Every other character is kept. Use it on user input before parsing.

Implementation

String toLatinDigits(String input) => String.fromCharCodes(
      input.codeUnits.map((c) {
        if (c >= _persianZero && c <= _persianZero + 9) {
          return c - _persianZero + _latinZero;
        }
        if (c >= _arabicIndicZero && c <= _arabicIndicZero + 9) {
          return c - _arabicIndicZero + _latinZero;
        }
        return c;
      }),
    );