normalize method
Normalizes a string of characters representing a phone number. This performs the following conversions: Punctuation is stripped. For ALPHA/VANITY numbers: Letters are converted to their numeric representation on a telephone keypad. The keypad used here is the one defined in ITU Recommendation E.161. This is only done if there are 3 or more letters in the number, to lessen the risk that such letters are typos. For other numbers: Wide-ascii digits are converted to normal ASCII (European) digits. Arabic-Indic numerals are converted to European numerals. Spurious alpha characters are stripped.
number
a string of characters representing a phone number.
returns the normalized string version of the phone number.
Implementation
String normalize(StringBuffer number) {
RegExpMatch? m = _validAlphaPhonePattern.firstMatch(number.toString());
if (m != null && m.group(0) == number.toString()) {
String normalized =
_normalizeHelper(number.toString(), _allNormalizationMappings, true);
number
..clear()
..write(normalized);
} else {
String normalized = normalizeDigitsOnly(number.toString());
number
..clear()
..write(normalized);
}
return number.toString();
}