containsMoreThanOneSlashInNationalNumber static method

bool containsMoreThanOneSlashInNationalNumber(
  1. PhoneNumber number,
  2. String candidate
)

Implementation

static bool containsMoreThanOneSlashInNationalNumber(
    PhoneNumber number, String candidate) {
  int firstSlashInBodyIndex = candidate.indexOf('/');
  if (firstSlashInBodyIndex < 0) {
    // No slashes, this is okay.
    return false;
  }
  // Now look for a second one.
  int secondSlashInBodyIndex =
      candidate.indexOf('/', firstSlashInBodyIndex + 1);
  if (secondSlashInBodyIndex < 0) {
    // Only one slash, this is okay.
    return false;
  }

  // If the first slash is after the country calling code, this is permitted.
  bool candidateHasCountryCode = (number.countryCodeSource ==
          PhoneNumber_CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN ||
      number.countryCodeSource ==
          PhoneNumber_CountryCodeSource.FROM_NUMBER_WITHOUT_PLUS_SIGN);
  if (candidateHasCountryCode &&
      PhoneNumberUtil.normalizeDigitsOnly(
              candidate.substring(0, firstSlashInBodyIndex)) ==
          '${number.countryCode}') {
    // Any more slashes and this is illegal.
    return candidate.substring(secondSlashInBodyIndex + 1).contains("/");
  }
  return true;
}