chooseFormattingPatternForNumber method

NumberFormat? chooseFormattingPatternForNumber(
  1. List<NumberFormat> availableFormats,
  2. String nationalNumber
)

availableFormats the available formats the phone number could be formatted into. nationalNumber a string of characters representing a phone number.

Implementation

NumberFormat? chooseFormattingPatternForNumber(
    List<NumberFormat> availableFormats, String nationalNumber) {
  for (var numFormat in availableFormats) {
    int size = numFormat.leadingDigitsPattern.length;
    if (size == 0 ||
        // We always use the last leading_digits_pattern, as it is the most detailed.
        RegExp(numFormat.leadingDigitsPattern[size - 1])
                .matchAsPrefix(nationalNumber) !=
            null) {
      if (matchesEntirely(RegExp(numFormat.pattern), nationalNumber)) {
        return numFormat;
      }
    }
  }
  return null;
}