Skip to content

Commit

Permalink
shortnumberinfo.cc updates: Using absl collections; using nullptr ins…
Browse files Browse the repository at this point in the history
…tead of NULL where needed.. (google#2750)
  • Loading branch information
penmetsaa authored Apr 7, 2022
1 parent 8695f9c commit 7b69a59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions cpp/src/phonenumbers/shortnumberinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, PhoneMetadata>()),
regions_where_emergency_numbers_must_be_exact_(new set<string>()) {
region_to_short_metadata_map_(new absl::flat_hash_map<string, PhoneMetadata>()),
regions_where_emergency_numbers_must_be_exact_(new absl::flat_hash_set<string>()) {
PhoneMetadataCollection metadata_collection;
if (!LoadCompiledInMetadata(&metadata_collection)) {
LOG(DFATAL) << "Could not parse compiled-in metadata.";
Expand All @@ -71,7 +71,7 @@ const PhoneMetadata* ShortNumberInfo::GetMetadataForRegion(
if (it != region_to_short_metadata_map_->end()) {
return &it->second;
}
return NULL;
return nullptr;
}

namespace {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand All @@ -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 "";
Expand Down
6 changes: 4 additions & 2 deletions cpp/src/phonenumbers/shortnumberinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -179,12 +181,12 @@ class ShortNumberInfo {
const scoped_ptr<const MatcherApi> matcher_api_;

// A mapping from a RegionCode to the PhoneMetadata for that region.
scoped_ptr<map<string, PhoneMetadata> >
scoped_ptr<absl::flat_hash_map<string, PhoneMetadata> >
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<set<string> >
scoped_ptr<absl::flat_hash_set<string> >
regions_where_emergency_numbers_must_be_exact_;

const i18n::phonenumbers::PhoneMetadata* GetMetadataForRegion(
Expand Down

0 comments on commit 7b69a59

Please sign in to comment.