cpp/src/phonenumbers/phonenumberutil.cc
// Converts number_to_parse to a form that we can parse and write it to
// national_number if it is written in RFC3966; otherwise extract a possible
// number out of it and write to national_number.
Converts number_to_parse to a form that we can parse and write it to
national_number if it is written in RFC3966; otherwise extract a possible
number out of it and write to national_number.
Converts number_to_parse to a form that we can parse and write it to national_number if it is written in RFC3966 ; otherwise extract a possible number out of it and write to national_number .
void PhoneNumberUtil::BuildNationalNumberForParsing(
    const string& number_to_parse, string* national_number) const {
  size_t index_of_phone_context = number_to_parse.find(kRfc3966PhoneContext);
  if (index_of_phone_context != string::npos) {
    size_t phone_context_start =
        index_of_phone_context + strlen(kRfc3966PhoneContext);
    if (phone_context_start < (number_to_parse.length() - 1) &&
        number_to_parse.at(phone_context_start) == kPlusSign[0]) {
      size_t phone_context_end = number_to_parse.find(';', phone_context_start);
      if (phone_context_end != string::npos) {
        StrAppend(
            national_number, number_to_parse.substr(
                phone_context_start, phone_context_end - phone_context_start));
      } else {
        StrAppend(national_number, number_to_parse.substr(phone_context_start));
      }
    }
    size_t index_of_rfc_prefix = number_to_parse.find(kRfc3966Prefix);
    int index_of_national_number = (index_of_rfc_prefix != string::npos) ?
        static_cast<int>(index_of_rfc_prefix + strlen(kRfc3966Prefix)) : 0;
    StrAppend(
        national_number,
        number_to_parse.substr(
            index_of_national_number,
            index_of_phone_context - index_of_national_number));
  } else {
    ExtractPossibleNumber(number_to_parse, national_number);
  }
  size_t index_of_isdn = national_number->find(kRfc3966IsdnSubaddress);
  if (index_of_isdn != string::npos) {
    national_number->erase(index_of_isdn);
  }
}
void PhoneNumberUtil :: BuildNationalNumberForParsing ( const string & number_to_parse , string * national_number ) const { size_t index_of_phone_context = number_to_parse . find ( kRfc3966PhoneContext ) ; if ( index_of_phone_context != string :: npos ) { size_t phone_context_start = index_of_phone_context + strlen ( kRfc3966PhoneContext ) ; if ( phone_context_start < ( number_to_parse . length ( ) - 1 ) && number_to_parse . at ( phone_context_start ) == kPlusSign [ 0 ] ) { size_t phone_context_end = number_to_parse . find ( ' ' , phone_context_start ) ; if ( phone_context_end != string :: npos ) { StrAppend ( national_number , number_to_parse . substr ( phone_context_start , phone_context_end - phone_context_start ) ) ; } else { StrAppend ( national_number , number_to_parse . substr ( phone_context_start ) ) ; } } size_t index_of_rfc_prefix = number_to_parse . find ( kRfc3966Prefix ) ; int index_of_national_number = ( index_of_rfc_prefix != string :: npos ) ? static_cast < int > ( index_of_rfc_prefix + strlen ( kRfc3966Prefix ) ) : 0 ; StrAppend ( national_number , number_to_parse . substr ( index_of_national_number , index_of_phone_context - index_of_national_number ) ) ; } else { ExtractPossibleNumber ( number_to_parse , national_number ) ; } size_t index_of_isdn = national_number -> find ( kRfc3966IsdnSubaddress ) ; if ( index_of_isdn != string :: npos ) { national_number -> erase ( index_of_isdn ) ; } }
Converts number_to_parse to a form that we can parse and write it to
national_number if it is written in RFC3966; otherwise extract a possible
number out of it and write to national_number.
Converts number_to_parse to a form that we can parse and write it to national_number if it is written in RFC3966 ; otherwise extract a possible number out of it and write to national_number .
// If the phone context contains a phone number prefix, we need to capture // it, whereas domains will be ignored. // Additional parameters might follow the phone context. If so, we will // remove them here because the parameters after phone context are not // important for parsing the phone number. // Now append everything between the "tel:" prefix and the phone-context. // This should include the national number, an optional extension or // isdn-subaddress component. Note we also handle the case when "tel:" is // missing, as we have seen in some of the phone number inputs. In that // case, we append everything from the beginning. // Extract a possible number from the string passed in (this strips leading // characters that could not be the start of a phone number.) // Delete the isdn-subaddress and everything after it if it is present. Note // extension won't appear at the same time with isdn-subaddress according to // paragraph 5.3 of the RFC3966 spec. // If both phone context and isdn-subaddress are absent but other parameters // are present, the parameters are left in nationalNumber. This is because // we are concerned about deleting content from a potential number string // when there is no strong evidence that the number is actually written in // RFC3966.