From 7b69a5946f9d26b86d794f0fd8deed5814944a7a Mon Sep 17 00:00:00 2001 From: penmetsaa Date: Thu, 7 Apr 2022 14:48:29 +0530 Subject: [PATCH] shortnumberinfo.cc updates: Using absl collections; using nullptr instead of NULL where needed.. (#2750) --- cpp/src/phonenumbers/shortnumberinfo.cc | 12 ++++++------ cpp/src/phonenumbers/shortnumberinfo.h | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cpp/src/phonenumbers/shortnumberinfo.cc b/cpp/src/phonenumbers/shortnumberinfo.cc index 2486a4f72f..8e5d12df94 100644 --- a/cpp/src/phonenumbers/shortnumberinfo.cc +++ b/cpp/src/phonenumbers/shortnumberinfo.cc @@ -45,8 +45,8 @@ bool LoadCompiledInMetadata(PhoneMetadataCollection* metadata) { ShortNumberInfo::ShortNumberInfo() : phone_util_(*PhoneNumberUtil::GetInstance()), matcher_api_(new RegexBasedMatcher()), - region_to_short_metadata_map_(new map()), - regions_where_emergency_numbers_must_be_exact_(new set()) { + region_to_short_metadata_map_(new absl::flat_hash_map()), + regions_where_emergency_numbers_must_be_exact_(new absl::flat_hash_set()) { PhoneMetadataCollection metadata_collection; if (!LoadCompiledInMetadata(&metadata_collection)) { LOG(DFATAL) << "Could not parse compiled-in metadata."; @@ -71,7 +71,7 @@ const PhoneMetadata* ShortNumberInfo::GetMetadataForRegion( if (it != region_to_short_metadata_map_->end()) { return &it->second; } - return NULL; + return nullptr; } namespace { @@ -273,7 +273,7 @@ void ShortNumberInfo::GetRegionCodeForShortNumberFromRegionList( phone_util_.GetNationalSignificantNumber(number, &national_number); for (const auto& region_code_it : region_codes) { const PhoneMetadata* phone_metadata = GetMetadataForRegion(region_code_it); - if (phone_metadata != NULL && + if (phone_metadata != nullptr && MatchesPossibleNumberAndNationalNumber(*matcher_api_, national_number, phone_metadata->short_code())) { // The number is valid for this region. @@ -302,7 +302,7 @@ string ShortNumberInfo::GetExampleShortNumberForCost(const string& region_code, if (!phone_metadata) { return ""; } - const PhoneNumberDesc* desc = NULL; + const PhoneNumberDesc* desc = nullptr; switch (cost) { case TOLL_FREE: desc = &(phone_metadata->toll_free()); @@ -318,7 +318,7 @@ string ShortNumberInfo::GetExampleShortNumberForCost(const string& region_code, // the other cost categories. break; } - if (desc != NULL && desc->has_example_number()) { + if (desc != nullptr && desc->has_example_number()) { return desc->example_number(); } return ""; diff --git a/cpp/src/phonenumbers/shortnumberinfo.h b/cpp/src/phonenumbers/shortnumberinfo.h index 856fa5214b..db54b48ed2 100644 --- a/cpp/src/phonenumbers/shortnumberinfo.h +++ b/cpp/src/phonenumbers/shortnumberinfo.h @@ -26,6 +26,8 @@ #include "phonenumbers/base/basictypes.h" #include "phonenumbers/base/memory/scoped_ptr.h" +#include "absl/container/flat_hash_set.h" +#include "absl/container/flat_hash_map.h" namespace i18n { namespace phonenumbers { @@ -179,12 +181,12 @@ class ShortNumberInfo { const scoped_ptr matcher_api_; // A mapping from a RegionCode to the PhoneMetadata for that region. - scoped_ptr > + scoped_ptr > region_to_short_metadata_map_; // In these countries, if extra digits are added to an emergency number, it no // longer connects to the emergency service. - scoped_ptr > + scoped_ptr > regions_where_emergency_numbers_must_be_exact_; const i18n::phonenumbers::PhoneMetadata* GetMetadataForRegion(