From ec308eb9e2274b9ea49f3eb52f047bcea6e9d77e Mon Sep 17 00:00:00 2001 From: Philip Liard Date: Thu, 16 Jun 2011 08:37:22 +0000 Subject: [PATCH] CPP: Internal function rename (CompareFirst -> OrderByFirst). --- cpp/src/phonenumberutil.cc | 5 +++-- cpp/src/phonenumberutil.h | 7 ------- cpp/src/stl_util.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 cpp/src/stl_util.h diff --git a/cpp/src/phonenumberutil.cc b/cpp/src/phonenumberutil.cc index 19e4b25bd..dfd9ad31a 100644 --- a/cpp/src/phonenumberutil.cc +++ b/cpp/src/phonenumberutil.cc @@ -39,6 +39,7 @@ #include "phonenumber.pb.h" #include "regexp_adapter.h" #include "regexp_cache.h" +#include "stl_util.h" #include "stringutil.h" #include "utf/unicodetext.h" #include "utf/utf.h" @@ -709,7 +710,7 @@ PhoneNumberUtil::PhoneNumberUtil() // Sort all the pairs in ascending order according to country calling code. sort(country_calling_code_to_region_code_map_->begin(), country_calling_code_to_region_code_map_->end(), - CompareFirst()); + OrderByFirst()); InitializeStaticMapsAndSets(); } @@ -1200,7 +1201,7 @@ void PhoneNumberUtil::GetRegionCodesForCountryCallingCode( pair range = equal_range( country_calling_code_to_region_code_map_->begin(), country_calling_code_to_region_code_map_->end(), - target_pair, CompareFirst()); + target_pair, OrderByFirst()); if (range.first != range.second) { region_codes->insert(region_codes->begin(), range.first->second->begin(), diff --git a/cpp/src/phonenumberutil.h b/cpp/src/phonenumberutil.h index 37f820c91..ca6921584 100644 --- a/cpp/src/phonenumberutil.h +++ b/cpp/src/phonenumberutil.h @@ -521,13 +521,6 @@ class PhoneNumberUtil : public Singleton { // achieve better performance. scoped_ptr > country_calling_code_to_region_code_map_; - struct CompareFirst { - bool operator()(const IntRegionsPair& p1, - const IntRegionsPair& p2) const { - return p1.first < p2.first; - } - }; - // The set of regions that share country calling code 1. scoped_ptr > nanpa_regions_; static const int kNanpaCountryCode = 1; diff --git a/cpp/src/stl_util.h b/cpp/src/stl_util.h new file mode 100644 index 000000000..ead643def --- /dev/null +++ b/cpp/src/stl_util.h @@ -0,0 +1,32 @@ +// Copyright (C) 2011 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef I18N_PHONENUMBERS_STL_UTIL_H_ +#define I18N_PHONENUMBERS_STL_UTIL_H_ + +namespace i18n { +namespace phonenumbers { + +// Compares the first attribute of two pairs. +struct OrderByFirst { + template + bool operator()(const T& p1, const T& p2) const { + return p1.first < p2.first; + } +}; + +} // namespace phonenumbers +} // namespace i18n + +#endif // I18N_PHONENUMBERS_STL_UTIL_H_