cpp/src/phonenumbers/phonenumberutil.cc
// Private constructor. Also takes care of initialisation.
Private constructor. Also takes care of initialisation.
Private constructor . Also takes care of initialisation .
PhoneNumberUtil::PhoneNumberUtil()
    : logger_(Logger::set_logger_impl(new NullLogger())),
      matcher_api_(new RegexBasedMatcher()),
      reg_exps_(new PhoneNumberRegExpsAndMappings),
      country_calling_code_to_region_code_map_(
          new std::vector<IntRegionsPair>()),
      nanpa_regions_(new std::set<string>()),
      region_to_metadata_map_(new std::map<string, PhoneMetadata>()),
      country_code_to_non_geographical_metadata_map_(
          new std::map<int, PhoneMetadata>) {
  Logger::set_logger_impl(logger_.get());
  PhoneMetadataCollection metadata_collection;
  if (!LoadCompiledInMetadata(&metadata_collection)) {
    LOG(DFATAL) << "Could not parse compiled-in metadata.";
    return;
  }
  std::map<int, std::list<string>* > country_calling_code_to_region_map;
  for (RepeatedPtrField<PhoneMetadata>::const_iterator it =
           metadata_collection.metadata().begin();
       it != metadata_collection.metadata().end();
       ++it) {
    const string& region_code = it->id();
    if (region_code == RegionCode::GetUnknown()) {
      continue;
    }
    int country_calling_code = it->country_code();
    if (kRegionCodeForNonGeoEntity == region_code) {
      country_code_to_non_geographical_metadata_map_->insert(
          std::make_pair(country_calling_code, *it));
    } else {
      region_to_metadata_map_->insert(std::make_pair(region_code, *it));
    }
    std::map<int, std::list<string>* >::iterator calling_code_in_map =
        country_calling_code_to_region_map.find(country_calling_code);
    if (calling_code_in_map != country_calling_code_to_region_map.end()) {
      if (it->main_country_for_code()) {
        calling_code_in_map->second->push_front(region_code);
      } else {
        calling_code_in_map->second->push_back(region_code);
      }
    } else {
      std::list<string>* list_with_region_code = new std::list<string>();
      list_with_region_code->push_back(region_code);
      country_calling_code_to_region_map.insert(
          std::make_pair(country_calling_code, list_with_region_code));
    }
    if (country_calling_code == kNanpaCountryCode) {
        nanpa_regions_->insert(region_code);
    }
  }
  country_calling_code_to_region_code_map_->insert(
      country_calling_code_to_region_code_map_->begin(),
      country_calling_code_to_region_map.begin(),
      country_calling_code_to_region_map.end());
  std::sort(country_calling_code_to_region_code_map_->begin(),
            country_calling_code_to_region_code_map_->end(), OrderByFirst());
}
PhoneNumberUtil :: PhoneNumberUtil ( ) : logger_ ( Logger :: set_logger_impl ( new NullLogger ( ) ) ) , matcher_api_ ( new RegexBasedMatcher ( ) ) , reg_exps_ ( new PhoneNumberRegExpsAndMappings ) , country_calling_code_to_region_code_map_ ( new std :: vector < IntRegionsPair > ( ) ) , nanpa_regions_ ( new std :: set < string > ( ) ) , region_to_metadata_map_ ( new std :: map < string , PhoneMetadata > ( ) ) , country_code_to_non_geographical_metadata_map_ ( new std :: map < int , PhoneMetadata > ) { Logger :: set_logger_impl ( logger_ . get ( ) ) ; PhoneMetadataCollection metadata_collection ; if ( ! LoadCompiledInMetadata ( & metadata_collection ) ) { LOG ( DFATAL ) << " " ; return ; } std :: map < int , std :: list < string > * > country_calling_code_to_region_map ; for ( RepeatedPtrField < PhoneMetadata > :: const_iterator it = metadata_collection . metadata ( ) . begin ( ) ; it != metadata_collection . metadata ( ) . end ( ) ; ++ it ) { const string & region_code = it -> id ( ) ; if ( region_code == RegionCode :: GetUnknown ( ) ) { continue ; } int country_calling_code = it -> country_code ( ) ; if ( kRegionCodeForNonGeoEntity == region_code ) { country_code_to_non_geographical_metadata_map_ -> insert ( std :: make_pair ( country_calling_code , * it ) ) ; } else { region_to_metadata_map_ -> insert ( std :: make_pair ( region_code , * it ) ) ; } std :: map < int , std :: list < string > * > :: iterator calling_code_in_map = country_calling_code_to_region_map . find ( country_calling_code ) ; if ( calling_code_in_map != country_calling_code_to_region_map . end ( ) ) { if ( it -> main_country_for_code ( ) ) { calling_code_in_map -> second -> push_front ( region_code ) ; } else { calling_code_in_map -> second -> push_back ( region_code ) ; } } else { std :: list < string > * list_with_region_code = new std :: list < string > ( ) ; list_with_region_code -> push_back ( region_code ) ; country_calling_code_to_region_map . insert ( std :: make_pair ( country_calling_code , list_with_region_code ) ) ; } if ( country_calling_code == kNanpaCountryCode ) { nanpa_regions_ -> insert ( region_code ) ; } } country_calling_code_to_region_code_map_ -> insert ( country_calling_code_to_region_code_map_ -> begin ( ) , country_calling_code_to_region_map . begin ( ) , country_calling_code_to_region_map . end ( ) ) ; std :: sort ( country_calling_code_to_region_code_map_ -> begin ( ) , country_calling_code_to_region_code_map_ -> end ( ) , OrderByFirst ( ) ) ; }
Private constructor.
Private constructor .
// TODO: Update the java version to put the contents of the init // method inside the constructor as well to keep both in sync. // Storing data in a temporary map to make it easier to find other regions // that share a country calling code when inserting data. // For most country calling codes, there will be only one region code. // Sort all the pairs in ascending order according to country calling code.