示例#1
0
        private bool MatchesEmergencyNumberHelper(string number, string regionCode,
                                                  bool allowPrefixMatch)
        {
            var possibleNumber = PhoneNumberUtil.ExtractPossibleNumber(number);

            if (possibleNumber.Length > 0 && PhoneNumberUtil.IsPlusChar(possibleNumber[0]))
            {
                // Returns false if the number starts with a plus sign. We don't believe dialing the country
                // code before emergency numbers (e.g. +1911) works, but later, if that proves to work, we can
                // add additional logic here to handle it.
                return(false);
            }

            var metadata = MetadataManager.GetShortNumberMetadataForRegion(regionCode);

            if (metadata == null || !metadata.HasEmergency)
            {
                return(false);
            }

            var normalizedNumber          = PhoneNumberUtil.NormalizeDigitsOnly(possibleNumber);
            var allowPrefixMatchForRegion =
                allowPrefixMatch && !RegionsWhereEmergencyNumbersMustBeExact.Contains(regionCode);

            return(matcherApi.MatchNationalNumber(normalizedNumber, metadata.Emergency,
                                                  allowPrefixMatchForRegion));
        }
 // Accrues digits and the plus sign to accruedInputWithoutFormatting for later use. If nextChar
 // contains a digit in non-ASCII format (e.g. the full-width version of digits), it is first
 // normalized to the ASCII version. The return value is nextChar itself, or its normalized
 // version, if nextChar is a digit in non-ASCII format. This method assumes its input is either a
 // digit or the plus sign.
 private char NormalizeAndAccrueDigitsAndPlusSign(char nextChar, bool rememberPosition)
 {
     if (PhoneNumberUtil.IsPlusChar(nextChar))
     {
         nextChar = PhoneNumberUtil.PLUS_SIGN;
         accruedInputWithoutFormatting.Append(nextChar);
     }
     else
     {
         if ((uint)(nextChar - '0') > 9)
         {
             nextChar = ((int)char.GetNumericValue(nextChar)).ToString()[0];
         }
         accruedInputWithoutFormatting.Append(nextChar);
         nationalNumber.Append(nextChar);
     }
     if (rememberPosition)
     {
         positionToRemember = accruedInputWithoutFormatting.Length;
     }
     return(nextChar);
 }
 private bool IsDigitOrLeadingPlusSign(char nextChar)
 {
     return(char.IsDigit(nextChar) ||
            accruedInput.Length == 1 &&
            PhoneNumberUtil.IsPlusChar(nextChar));
 }