Lines Matching defs:number
69 // find numbers in text and to decide what is a viable phone number. This
113 // any extension component of the number, after the main national number is
191 // Returns true when one national number is the suffix of the other or both are
221 // number is changed, MaybeStripExtension needs to be updated.
276 // other as a number + extension. The fourth one covers the special case of
289 // the extension number following.
307 // extensions. However, the second pattern is more liberal on number of
308 // commas that acts as extension labels, so we have strict cap on number of
317 // Normalizes a string of characters representing a phone number by replacing
321 // number - a pointer to a string of characters representing a phone number to
324 // replaced by in the normalized version of the phone number
326 // replaced should be stripped from the number. If this is false, they will be
327 // left unchanged in the number.
330 string* number) {
331 DCHECK(number);
333 number_as_unicode.PointToUTF8(number->data(), static_cast<int>(number->size()));
336 number->clear();
355 number->assign(normalized_number);
358 // Returns true if there is any possible number data set for a particular
394 // represents that a particular number type can't be
404 // Helper method to check a number against possible lengths for this number
407 const string& number, const PhoneMetadata& metadata,
416 // is guaranteed not to match the length of any real phone number).
429 return TestNumberLength(number, metadata, PhoneNumberUtil::MOBILE);
460 int actual_length = static_cast<int>(number.length());
482 // Helper method to check a number against possible lengths for this region,
486 const string& number, const PhoneMetadata& metadata) {
487 return TestNumberLength(number, metadata, PhoneNumberUtil::UNKNOWN);
490 // Returns a new phone number containing only the fields needed to uniquely
491 // identify a phone number, rather than any fields that capture the context in
492 // which the phone number was created.
495 void CopyCoreFieldsOnly(const PhoneNumber& number, PhoneNumber* pruned_number) {
496 pruned_number->set_country_code(number.country_code());
497 pruned_number->set_national_number(number.national_number());
498 if (!number.extension().empty()) {
499 pruned_number->set_extension(number.extension());
501 if (number.italian_leading_zero()) {
505 number.number_of_leading_zeros());
509 // Determines whether the given number is a national number match for the given
512 const string& number, const PhoneNumberDesc& desc) {
513 return matcher_api.MatchNationalNumber(number, desc, false);
530 // formatting alpha numbers, as they show the intended number groupings.
639 // alpha characters and digits in the phone number. Does not include extension
650 // them. The second expression restricts the number of digits to three or
675 // any of the characters in this map must not be removed from a number when
686 // numbers. This includes digits, ascii letters and number grouping symbols
721 // Regular expression of acceptable characters that may start a phone number
725 // alpha characters, although they may be used later in the number. It also
727 // parsing and is of no information value when parsing a number. The string
733 // a second number.
740 // number if this was a match.
757 // phone number may have an extension prefix appended, followed by 1 or more
761 // We use this pattern to check if the phone number has at least three letters
762 // in it - if so, then we treat it as a number where some phone-number digits
772 // Regular expression of valid global-number-digits for the phone-context
1000 bool PhoneNumberUtil::StartsWithPlusCharsPattern(const string& number)
1003 reg_exps_->regexp_factory_->CreateInput(number));
1011 void PhoneNumberUtil::TrimUnwantedEndChars(string* number) const {
1012 DCHECK(number);
1014 number_as_unicode.PointToUTF8(number->data(), static_cast<int>(number->size()));
1017 number->clear();
1031 number->assign(UnicodeText::UTF8Substring(number_as_unicode.begin(),
1040 // followed by a single digit, separated by valid phone number punctuation.
1121 void PhoneNumberUtil::Format(const PhoneNumber& number,
1125 if (number.national_number() == 0) {
1126 const string& raw_input = number.raw_input();
1129 // This is the only case where a number can be formatted as E164 without a
1130 // leading '+' symbol (but the original number wasn't parseable anyway).
1137 int country_calling_code = number.country_code();
1139 GetNationalSignificantNumber(number, &national_significant_number);
1142 // since no formatting of the national number needs to be applied.
1166 MaybeAppendFormattedExtension(number, *metadata, number_format,
1173 const PhoneNumber& number,
1178 int country_calling_code = number.country_code();
1184 GetNationalSignificantNumber(number, &national_significant_number);
1198 // If no pattern above is matched, we format the number as a whole.
1226 MaybeAppendFormattedExtension(number, *metadata, NATIONAL, formatted_number);
1232 const PhoneNumber& number,
1235 int country_calling_code = number.country_code();
1237 GetNationalSignificantNumber(number, &national_significant_number);
1254 MaybeAppendFormattedExtension(number, *metadata, NATIONAL, formatted_number);
1267 const PhoneNumber& number,
1271 number,
1274 // result in a number we can dial. For this reason, we treat the empty
1276 !number.preferred_domestic_carrier_code().empty()
1277 ? number.preferred_domestic_carrier_code()
1283 const PhoneNumber& number,
1287 int country_calling_code = number.country_code();
1289 formatted_number->assign(number.has_raw_input() ? number.raw_input() : "");
1295 // the main number.
1296 PhoneNumber number_no_extension(number);
1310 // result in a number we can dial. For this reason, we treat the empty
1357 // phone types we return the number in international format here.
1371 // region, so if a number is not a valid regular length phone number, we
1384 const PhoneNumber& number,
1389 VLOG(1) << "Trying to format number from invalid region " << calling_from
1391 Format(number, INTERNATIONAL, formatted_number);
1394 int country_code = number.country_code();
1396 GetNationalSignificantNumber(number, &national_significant_number);
1405 Format(number, NATIONAL, formatted_number);
1411 // country calling code of the number and the country calling code of the
1422 Format(number, NATIONAL, formatted_number);
1433 // international format of the number is returned since we would not know
1451 MaybeAppendFormattedExtension(number, *metadata_for_region, INTERNATIONAL,
1462 void PhoneNumberUtil::FormatInOriginalFormat(const PhoneNumber& number,
1467 if (number.has_raw_input() && !HasFormattingPatternForNumber(number)) {
1469 // format the number as a group without national prefix.
1470 formatted_number->assign(number.raw_input());
1473 if (!number.has_country_code_source()) {
1474 Format(number, NATIONAL, formatted_number);
1477 switch (number.country_code_source()) {
1479 Format(number, INTERNATIONAL, formatted_number);
1482 FormatOutOfCountryCallingNumber(number, region_calling_from,
1486 Format(number, INTERNATIONAL, formatted_number);
1493 GetRegionCodeForCountryCode(number.country_code(), ®ion_code);
1503 Format(number, NATIONAL, formatted_number);
1506 // Otherwise, we check if the original number was entered with a national
1508 if (RawInputContainsNationalPrefix(number.raw_input(), national_prefix,
1511 Format(number, NATIONAL, formatted_number);
1518 GetNationalSignificantNumber(number, &national_number);
1524 // The format rule could still be NULL here if the national number was 0
1529 Format(number, NATIONAL, formatted_number);
1532 // When the format we apply to this number doesn't contain national
1545 Format(number, NATIONAL, formatted_number);
1552 // National prefix not used when formatting this number.
1553 Format(number, NATIONAL, formatted_number);
1561 FormatByPattern(number, NATIONAL, number_formats, formatted_number);
1565 // return the formatted phone number; otherwise we return the raw input the
1567 if (!formatted_number->empty() && !number.raw_input().empty()) {
1570 string normalized_raw_input(number.raw_input());
1573 formatted_number->assign(number.raw_input());
1590 // number if the assumed national prefix is removed (777123 won't be
1603 const PhoneNumber& number) const {
1604 int country_calling_code = number.country_code();
1613 GetNationalSignificantNumber(number, &national_number);
1621 const PhoneNumber& number,
1626 if (number.raw_input().empty()) {
1627 FormatOutOfCountryCallingNumber(number, calling_from, formatted_number);
1630 int country_code = number.country_code();
1632 formatted_number->assign(number.raw_input());
1636 // this by comparing the number in raw_input with the parsed number.
1637 string raw_input_copy(number.raw_input());
1638 // Normalize punctuation. We retain number grouping symbols such as " " only.
1641 // Now we trim everything before the first three digits in the parsed number.
1644 // national number was less than three digits, we don't trim anything at all.
1646 GetNationalSignificantNumber(number, &national_number);
1691 // multiple international prefixes, the international format of the number is
1708 VLOG(1) << "Trying to format number from invalid region " << calling_from
1770 // contains only information on how the national significant number
1784 const scoped_ptr<RegExpInput> number(
1786 if (reg_exps_->separator_pattern_->Consume(number.get())) {
1787 formatted_number->assign(number->ToString());
1806 void PhoneNumberUtil::FormatNsn(const string& number,
1811 FormatNsnWithCarrier(number, metadata, number_format, "", formatted_number);
1814 // Note in some regions, the national number can be written in two completely
1819 void PhoneNumberUtil::FormatNsnWithCarrier(const string& number,
1825 // When the intl_number_formats exists, we use that to format national number
1832 ChooseFormattingPatternForNumber(available_formats, number);
1834 formatted_number->assign(number);
1836 FormatNsnUsingPatternWithCarrier(number, *formatting_pattern, number_format,
1841 // Appends the formatted extension of a phone number, if the phone number had an
1844 const PhoneNumber& number,
1849 if (number.has_extension() && number.extension().length() > 0) {
1851 StrAppend(formatted_number, kRfc3966ExtnPrefix, number.extension());
1855 number.extension());
1857 StrAppend(formatted_number, kDefaultExtnPrefix, number.extension());
1903 void PhoneNumberUtil::GetRegionCodeForNumber(const PhoneNumber& number,
1906 int country_calling_code = number.country_code();
1918 GetRegionCodeForNumberFromRegionList(number, region_codes, region_code);
1923 const PhoneNumber& number, const std::list<string>& region_codes,
1927 GetNationalSignificantNumber(number, &national_number);
1934 const scoped_ptr<RegExpInput> number(
1937 GetRegExp(metadata->leading_digits()).Consume(number.get())) {
1964 // Gets a valid fixed-line number for the specified region_code. Returns false
1966 // if no number exists.
1968 PhoneNumber* number) const {
1969 DCHECK(number);
1970 return GetExampleNumberForType(region_code, FIXED_LINE, number);
1974 PhoneNumber* number) const {
1975 DCHECK(number);
1981 // We start off with a valid fixed-line number since every country supports
1982 // this. Alternatively we could start with a different number type, since
1983 // fixed-line numbers typically have a wide breadth of valid number lengths
1984 // and we may have to make it very short before we get an invalid number.
1993 // Try and make the number invalid. We do this by changing the length. We try
1994 // reducing the length of the number, since currently no region has a number
1996 // making the number longer, which is another alternative. We could also use
1997 // the possible number pattern to extract the possible lengths of the number
2000 // We don't want to return a number that can't be parsed, so we check the
2001 // number is long enough. We try all possible lengths because phone number
2002 // plans often have overlapping prefixes so the number 123456 might be valid
2003 // as a fixed-line number, and 12345 as a mobile number. It would be faster to
2017 number->MergeFrom(possibly_valid_number);
2026 // Gets a valid number for the specified region_code and type. Returns false if
2028 // no number exists.
2032 PhoneNumber* number) const {
2033 DCHECK(number);
2042 ErrorType success = Parse(desc->example_number(), region_code, number);
2046 LOG(ERROR) << "Error parsing example number ("
2055 PhoneNumber* number) const {
2056 DCHECK(number);
2060 if (GetExampleNumberForType(region_code, type, number)) {
2064 // If there wasn't an example number for a region, try the non-geographical
2078 RegionCode::GetUnknown(), number);
2082 LOG(ERROR) << "Error parsing example number ("
2092 int country_calling_code, PhoneNumber* number) const {
2093 DCHECK(number);
2099 // through different types to find the example number. We don't check
2100 // fixed-line or personal number since they aren't used by non-geographical
2112 RegionCode::GetUnknown(), number);
2116 LOG(ERROR) << "Error parsing example number ("
2130 PhoneNumber* number) const {
2131 DCHECK(number);
2132 return ParseHelper(number_to_parse, default_region, false, true, number);
2138 PhoneNumber* number) const {
2139 DCHECK(number);
2140 return ParseHelper(number_to_parse, default_region, true, true, number);
2144 // the number to parse starts with a + symbol so that we can attempt to infer
2145 // the country from the number. Returns false if it cannot use the region
2151 const scoped_ptr<RegExpInput> number(
2153 if (!reg_exps_->plus_chars_pattern_->Consume(number.get())) {
2162 // number out of it and write to national_number.
2169 // If the phone context contains a phone number prefix, we need to capture
2175 // important for parsing the phone number.
2187 // This should include the national number, an optional extension or
2189 // missing, as we have seen in some of the phone number inputs. In that
2200 // Extract a possible number from the string passed in (this strips leading
2201 // characters that could not be the start of a phone number.)
2214 // we are concerned about deleting content from a potential number string
2215 // when there is no strong evidence that the number is actually written in
2234 VLOG(2) << "The string supplied did not seem to be a phone number.";
2248 // data and we want to have the non-normalised number here.
2255 // Check to see if the number is given in international format so we know
2256 // whether this number is from the default country or not.
2289 // Note that the national number was already normalized by
2294 VLOG(2) << "The string supplied is too short to be a phone number.";
2305 // Otherwise, we don't do the stripping, since the original number could be
2306 // a valid short number.
2321 VLOG(2) << "The string supplied is too short to be a phone number.";
2325 VLOG(2) << "The string supplied is too long to be a phone number.";
2338 // Attempts to extract a possible number from the string passed in. This
2340 // phone number. Characters that can be used to start a phone number are
2342 // found in the number passed in, an empty string is returned. This function
2347 // first number is parsed correctly.
2348 void PhoneNumberUtil::ExtractPossibleNumber(const string& number,
2353 number_as_unicode.PointToUTF8(number.data(), static_cast<int>(number.size()));
2389 bool PhoneNumberUtil::IsPossibleNumber(const PhoneNumber& number) const {
2390 ValidationResult result = IsPossibleNumberWithReason(number);
2395 const PhoneNumber& number, const PhoneNumberType type) const {
2396 ValidationResult result = IsPossibleNumberForTypeWithReason(number, type);
2401 const string& number,
2404 if (Parse(number, region_dialing_from, &number_proto) == NO_PARSING_ERROR) {
2412 const PhoneNumber& number) const {
2413 return IsPossibleNumberForTypeWithReason(number, PhoneNumberUtil::UNKNOWN);
2417 PhoneNumberUtil::IsPossibleNumberForTypeWithReason(const PhoneNumber& number,
2420 GetNationalSignificantNumber(number, &national_number);
2421 int country_code = number.country_code();
2424 // GetRegionCodeForNumber will not work if the number is possible but not
2426 // number pattern differs between various regions (Saint Helena and Tristan da
2441 bool PhoneNumberUtil::TruncateTooLongNumber(PhoneNumber* number) const {
2442 if (IsValidNumber(*number)) {
2445 PhoneNumber number_copy(*number);
2446 uint64 national_number = number->national_number();
2455 number->set_national_number(national_number);
2460 const PhoneNumber& number) const {
2462 GetRegionCodeForNumber(number, ®ion_code);
2464 GetMetadataForRegionOrCallingCode(number.country_code(), region_code);
2469 GetNationalSignificantNumber(number, &national_significant_number);
2473 bool PhoneNumberUtil::IsValidNumber(const PhoneNumber& number) const {
2475 GetRegionCodeForNumber(number, ®ion_code);
2476 return IsValidNumberForRegion(number, region_code);
2479 bool PhoneNumberUtil::IsValidNumberForRegion(const PhoneNumber& number,
2481 int country_code = number.country_code();
2488 // number does not match that of the region code.
2492 GetNationalSignificantNumber(number, &national_number);
2519 // Note that if the national number is all "0"s, the last "0" is not
2533 // Check if any possible number lengths are present; if so, we use them to
2536 // already checked before checking a specific number type.
2550 VLOG(4) << "Number type unknown - doesn't match general national number"
2555 VLOG(4) << "Number is a premium number.";
2559 VLOG(4) << "Number is a toll-free number.";
2563 VLOG(4) << "Number is a shared cost number.";
2567 VLOG(4) << "Number is a VOIP (Voice over IP) number.";
2571 VLOG(4) << "Number is a personal number.";
2575 VLOG(4) << "Number is a pager number.";
2583 VLOG(4) << "Number is a voicemail number.";
2591 VLOG(4) << "Fixed-line and mobile patterns equal, number is fixed-line"
2595 VLOG(4) << "Fixed-line and mobile patterns differ, but number is "
2599 VLOG(4) << "Number is a fixed line number.";
2602 // Otherwise, test to see if the number is mobile. Only do this if certain
2606 VLOG(4) << "Number is a mobile number.";
2609 VLOG(4) << "Number type unknown - doesn\'t match any specific number type"
2615 const PhoneNumber& number,
2619 // national prefix. Ensure the number of leading zeros is at least 0 so we
2621 StrAppend(national_number, number.italian_leading_zero() ?
2622 string(std::max(number.number_of_leading_zeros(), 0), '0') : "");
2623 StrAppend(national_number, number.national_number());
2627 const PhoneNumber& number) const {
2629 GetRegionCodeForNumber(number, ®ion_code);
2634 // If a country doesn't use a national prefix, and this number doesn't have an
2637 if (!metadata->has_national_prefix() && !number.italian_leading_zero()) {
2641 PhoneNumberType type = GetNumberType(number);
2642 int country_calling_code = number.country_code();
2654 return GetLengthOfNationalDestinationCode(number);
2658 const PhoneNumber& number) const {
2659 PhoneNumber copied_proto(number);
2660 if (number.has_extension()) {
2685 if (GetNumberType(number) == MOBILE) {
2689 // mobile token, which also forms part of the national significant number.
2691 // the rest of the phone number.
2693 GetCountryMobileToken(number.country_code(), &mobile_token);
2713 void PhoneNumberUtil::NormalizeDigitsOnly(string* number) const {
2714 DCHECK(number);
2718 non_digits_pattern.GlobalReplace(number, "");
2720 number->assign(NormalizeUTF8::NormalizeDecimalDigits(*number));
2723 void PhoneNumberUtil::NormalizeDiallableCharsOnly(string* number) const {
2724 DCHECK(number);
2726 true /* remove non matches */, number);
2729 bool PhoneNumberUtil::IsAlphaNumber(const string& number) const {
2730 if (!IsViablePhoneNumber(number)) {
2731 // Number is too short, or doesn't match the basic phone number pattern.
2734 // Copy the number, since we are going to try and strip the extension from it.
2735 string number_copy(number);
2741 void PhoneNumberUtil::ConvertAlphaCharactersInNumber(string* number) const {
2742 DCHECK(number);
2743 NormalizeHelper(reg_exps_->alpha_phone_mappings_, false, number);
2746 // Normalizes a string of characters representing a phone number. This performs
2752 // E.161. This is only done if there are 3 or more letters in the number, to
2758 void PhoneNumberUtil::Normalize(string* number) const {
2759 DCHECK(number);
2760 if (reg_exps_->valid_alpha_phone_pattern_->PartialMatch(*number)) {
2761 NormalizeHelper(reg_exps_->alpha_phone_mappings_, true, number);
2763 NormalizeDigitsOnly(number);
2766 // Checks to see if the string of characters could possibly be a phone number at
2769 // method does not require the number to be normalized in advance - but does
2770 // assume that leading non-number symbols have been removed, such as by the
2772 bool PhoneNumberUtil::IsViablePhoneNumber(const string& number) const {
2773 if (number.length() < kMinLengthForNsn) {
2776 return reg_exps_->valid_phone_number_pattern_->FullMatch(number);
2779 // Strips the IDD from the start of the number if present. Helper function used
2782 string* number) const {
2783 DCHECK(number);
2785 reg_exps_->regexp_factory_->CreateInput(*number));
2799 number->assign(number_copy->ToString());
2805 // Strips any international prefix (such as +, 00, 011) present in the number
2806 // provided, normalizes the resulting number, and indicates if an international
2810 // the region we think this number may be dialed in.
2812 // number, otherwise false if the number did not seem to be in international
2817 string* number) const {
2818 DCHECK(number);
2819 if (number->empty()) {
2823 reg_exps_->regexp_factory_->CreateInput(*number));
2825 number->assign(number_string_piece->ToString());
2826 // Can now normalize the rest of the number since we've consumed the "+"
2828 Normalize(number);
2834 Normalize(number);
2835 return ParsePrefixAsIdd(idd_pattern, number)
2840 // Strips any national prefix (such as 0, 1) present in the number provided.
2841 // The number passed in should be the normalized telephone number that we wish
2843 // region that we think this number is from. Returns true if a national prefix
2847 string* number,
2849 DCHECK(number);
2853 if (number->empty() || possible_national_prefix.empty()) {
2858 // We use two copies here since Consume modifies the phone number, and if the
2859 // first if-clause fails the number will already be changed.
2861 reg_exps_->regexp_factory_->CreateInput(*number));
2863 reg_exps_->regexp_factory_->CreateInput(*number));
2864 string number_string_copy(*number);
2867 // Check if the original number is viable.
2869 IsMatch(*matcher_api_, *number, general_desc);
2883 // We make the transformation and check that the resultant number is still
2884 // viable. If so, replace the number and return.
2891 number->assign(number_string_copy);
2909 number->assign(number_copy_as_string);
2920 // Strips any extension (as in, the part of the number dialled after the call is
2922 // the number, and returns it. The number passed in should be non-normalized.
2923 bool PhoneNumberUtil::MaybeStripExtension(string* number, std::string* extension)
2925 DCHECK(number);
2934 string number_copy(*number);
2944 // If we find a potential extension, and the number preceding this is a
2945 // viable number, we assume it is an extension.
2951 number->assign(number_copy);
2994 // Tries to extract a country calling code from a number. Country calling codes
2997 // is dialing from, if this is present in the number, and looking at the next
3000 // - by comparing the start of the number and the country calling code of the
3001 // default region. If the number is not considered possible for the numbering
3004 // country calling code. If this number is considered a possible number, then
3034 VLOG(2) << "Phone number had an IDD, but after this was not "
3035 << "long enough to be a viable phone number.";
3047 // Check to see if the number starts with the country calling code for the
3049 // checks on the validity of the number before and after.
3063 // If the number was not valid before but is valid now, or if it was too
3064 // long before, we consider the number with the country code stripped to
3089 // We only are about the fields that uniquely define a number, so we copy
3160 // phone number.
3167 // First see if the second number has an implicit country calling code, by
3176 // The second number has no country calling code. EXACT_MATCH is no longer
3178 // first number, and if EXACT_MATCH is returned, we replace this with
3194 // If the first number didn't have a valid country calling code, then we
3195 // parse the second number without one as well.
3204 // phone number.
3214 const PhoneNumber& number) const {
3216 GetRegionCodeForNumber(number, ®ion_code);
3224 GetNationalSignificantNumber(number, &national_significant_number);