#include "phonenumbers/phonenumberutil.h"
#include <algorithm>
#include <cctype>
#include <cstring>
#include <iterator>
#include <map>
#include <utility>
#include <vector>
#include <unicode/uchar.h>
#include <unicode/utf8.h>
#include "phonenumbers/asyoutypeformatter.h"
#include "phonenumbers/base/basictypes.h"
#include "phonenumbers/base/logging.h"
#include "phonenumbers/base/memory/singleton.h"
#include "phonenumbers/default_logger.h"
#include "phonenumbers/encoding_utils.h"
#include "phonenumbers/matcher_api.h"
#include "phonenumbers/metadata.h"
#include "phonenumbers/normalize_utf8.h"
#include "phonenumbers/phonemetadata.pb.h"
#include "phonenumbers/phonenumber.h"
#include "phonenumbers/phonenumber.pb.h"
#include "phonenumbers/regex_based_matcher.h"
#include "phonenumbers/regexp_adapter.h"
#include "phonenumbers/regexp_cache.h"
#include "phonenumbers/regexp_factory.h"
#include "phonenumbers/region_code.h"
#include "phonenumbers/stl_util.h"
#include "phonenumbers/stringutil.h"
#include "phonenumbers/utf/unicodetext.h"
#include "phonenumbers/utf/utf.h"
namespace i18n {
namespace phonenumbers {
RepeatedField;
OrderByFirst;
const size_t PhoneNumberUtil::kMinLengthForNsn;
const size_t PhoneNumberUtil::kMaxLengthForNsn;
const size_t PhoneNumberUtil::kMaxLengthCountryCode;
const int PhoneNumberUtil::kNanpaCountryCode;
const char PhoneNumberUtil::kPlusChars[] = …;
const char PhoneNumberUtil::kValidPunctuation[] = …
"-x\xE2\x80\x90-\xE2\x80\x95\xE2\x88\x92\xE3\x83\xBC\xEF\xBC\x8D-\xEF\xBC"
"\x8F \xC2\xA0\xC2\xAD\xE2\x80\x8B\xE2\x81\xA0\xE3\x80\x80()\xEF\xBC\x88"
"\xEF\xBC\x89\xEF\xBC\xBB\xEF\xBC\xBD.\\[\\]/~\xE2\x81\x93\xE2\x88\xBC";
const char PhoneNumberUtil::kCaptureUpToSecondNumberStart[] = …;
const char PhoneNumberUtil::kRegionCodeForNonGeoEntity[] = …;
namespace {
const char kPlusSign[] = …;
const char kStarSign[] = …;
const char kRfc3966ExtnPrefix[] = …;
const char kRfc3966Prefix[] = …;
const char kRfc3966PhoneContext[] = …;
const char kRfc3966IsdnSubaddress[] = …;
const char kDigits[] = …;
const char kValidAlpha[] = …;
const char kDefaultExtnPrefix[] = …;
const char kPossibleSeparatorsBetweenNumberAndExtLabel[] = …;
const char kPossibleCharsAfterExtLabel[] = …;
const char kOptionalExtSuffix[] = …;
bool LoadCompiledInMetadata(PhoneMetadataCollection* metadata) { … }
const PhoneNumberDesc* GetNumberDescByType(
const PhoneMetadata& metadata,
PhoneNumberUtil::PhoneNumberType type) { … }
void PrefixNumberWithCountryCallingCode(
int country_calling_code,
PhoneNumberUtil::PhoneNumberFormat number_format,
string* formatted_number) { … }
bool IsNationalNumberSuffixOfTheOther(const PhoneNumber& first_number,
const PhoneNumber& second_number) { … }
char32 ToUnicodeCodepoint(const char* unicode_char) { … }
std::string ExtnDigits(int max_length) { … }
std::string CreateExtnPattern(bool for_parsing) { … }
void NormalizeHelper(const std::map<char32, char>& normalization_replacements,
bool remove_non_matches,
string* number) { … }
bool DescHasPossibleNumberData(const PhoneNumberDesc& desc) { … }
bool DescHasData(const PhoneNumberDesc& desc) { … }
void GetSupportedTypesForMetadata(
const PhoneMetadata& metadata,
std::set<PhoneNumberUtil::PhoneNumberType>* types) { … }
PhoneNumberUtil::ValidationResult TestNumberLength(
const string& number, const PhoneMetadata& metadata,
PhoneNumberUtil::PhoneNumberType type) { … }
PhoneNumberUtil::ValidationResult TestNumberLength(
const string& number, const PhoneMetadata& metadata) { … }
void CopyCoreFieldsOnly(const PhoneNumber& number, PhoneNumber* pruned_number) { … }
bool IsMatch(const MatcherApi& matcher_api,
const string& number, const PhoneNumberDesc& desc) { … }
}
void PhoneNumberUtil::SetLogger(Logger* logger) { … }
class PhoneNumberRegExpsAndMappings { … };
PhoneNumberUtil::PhoneNumberUtil()
: … { … }
PhoneNumberUtil::~PhoneNumberUtil() { … }
void PhoneNumberUtil::GetSupportedRegions(std::set<string>* regions)
const { … }
void PhoneNumberUtil::GetSupportedGlobalNetworkCallingCodes(
std::set<int>* calling_codes) const { … }
void PhoneNumberUtil::GetSupportedCallingCodes(
std::set<int>* calling_codes) const { … }
void PhoneNumberUtil::GetSupportedTypesForRegion(
const string& region_code,
std::set<PhoneNumberType>* types) const { … }
void PhoneNumberUtil::GetSupportedTypesForNonGeoEntity(
int country_calling_code,
std::set<PhoneNumberType>* types) const { … }
PhoneNumberUtil* PhoneNumberUtil::GetInstance() { … }
const string& PhoneNumberUtil::GetExtnPatternsForMatching() const { … }
bool PhoneNumberUtil::StartsWithPlusCharsPattern(const string& number)
const { … }
bool PhoneNumberUtil::ContainsOnlyValidDigits(const string& s) const { … }
void PhoneNumberUtil::TrimUnwantedEndChars(string* number) const { … }
bool PhoneNumberUtil::IsFormatEligibleForAsYouTypeFormatter(
const string& format) const { … }
bool PhoneNumberUtil::FormattingRuleHasFirstGroupOnly(
const string& national_prefix_formatting_rule) const { … }
void PhoneNumberUtil::GetNddPrefixForRegion(const string& region_code,
bool strip_non_digits,
string* national_prefix) const { … }
bool PhoneNumberUtil::IsValidRegionCode(const string& region_code) const { … }
bool PhoneNumberUtil::HasValidCountryCallingCode(
int country_calling_code) const { … }
const PhoneMetadata* PhoneNumberUtil::GetMetadataForRegion(
const string& region_code) const { … }
const PhoneMetadata* PhoneNumberUtil::GetMetadataForNonGeographicalRegion(
int country_calling_code) const { … }
void PhoneNumberUtil::Format(const PhoneNumber& number,
PhoneNumberFormat number_format,
string* formatted_number) const { … }
void PhoneNumberUtil::FormatByPattern(
const PhoneNumber& number,
PhoneNumberFormat number_format,
const RepeatedPtrField<NumberFormat>& user_defined_formats,
string* formatted_number) const { … }
void PhoneNumberUtil::FormatNationalNumberWithCarrierCode(
const PhoneNumber& number,
const string& carrier_code,
string* formatted_number) const { … }
const PhoneMetadata* PhoneNumberUtil::GetMetadataForRegionOrCallingCode(
int country_calling_code, const string& region_code) const { … }
void PhoneNumberUtil::FormatNationalNumberWithPreferredCarrierCode(
const PhoneNumber& number,
const string& fallback_carrier_code,
string* formatted_number) const { … }
void PhoneNumberUtil::FormatNumberForMobileDialing(
const PhoneNumber& number,
const string& calling_from,
bool with_formatting,
string* formatted_number) const { … }
void PhoneNumberUtil::FormatOutOfCountryCallingNumber(
const PhoneNumber& number,
const string& calling_from,
string* formatted_number) const { … }
void PhoneNumberUtil::FormatInOriginalFormat(const PhoneNumber& number,
const string& region_calling_from,
string* formatted_number) const { … }
bool PhoneNumberUtil::RawInputContainsNationalPrefix(
const string& raw_input,
const string& national_prefix,
const string& region_code) const { … }
bool PhoneNumberUtil::HasFormattingPatternForNumber(
const PhoneNumber& number) const { … }
void PhoneNumberUtil::FormatOutOfCountryKeepingAlphaChars(
const PhoneNumber& number,
const string& calling_from,
string* formatted_number) const { … }
const NumberFormat* PhoneNumberUtil::ChooseFormattingPatternForNumber(
const RepeatedPtrField<NumberFormat>& available_formats,
const string& national_number) const { … }
void PhoneNumberUtil::FormatNsnUsingPatternWithCarrier(
const string& national_number,
const NumberFormat& formatting_pattern,
PhoneNumberUtil::PhoneNumberFormat number_format,
const string& carrier_code,
string* formatted_number) const { … }
void PhoneNumberUtil::FormatNsnUsingPattern(
const string& national_number,
const NumberFormat& formatting_pattern,
PhoneNumberUtil::PhoneNumberFormat number_format,
string* formatted_number) const { … }
void PhoneNumberUtil::FormatNsn(const string& number,
const PhoneMetadata& metadata,
PhoneNumberFormat number_format,
string* formatted_number) const { … }
void PhoneNumberUtil::FormatNsnWithCarrier(const string& number,
const PhoneMetadata& metadata,
PhoneNumberFormat number_format,
const string& carrier_code,
string* formatted_number) const { … }
void PhoneNumberUtil::MaybeAppendFormattedExtension(
const PhoneNumber& number,
const PhoneMetadata& metadata,
PhoneNumberFormat number_format,
string* formatted_number) const { … }
bool PhoneNumberUtil::IsNANPACountry(const string& region_code) const { … }
void PhoneNumberUtil::GetRegionCodesForCountryCallingCode(
int country_calling_code,
std::list<string>* region_codes) const { … }
void PhoneNumberUtil::GetRegionCodeForCountryCode(
int country_calling_code,
string* region_code) const { … }
void PhoneNumberUtil::GetRegionCodeForNumber(const PhoneNumber& number,
string* region_code) const { … }
void PhoneNumberUtil::GetRegionCodeForNumberFromRegionList(
const PhoneNumber& number, const std::list<string>& region_codes,
string* region_code) const { … }
int PhoneNumberUtil::GetCountryCodeForRegion(const string& region_code) const { … }
int PhoneNumberUtil::GetCountryCodeForValidRegion(
const string& region_code) const { … }
bool PhoneNumberUtil::GetExampleNumber(const string& region_code,
PhoneNumber* number) const { … }
bool PhoneNumberUtil::GetInvalidExampleNumber(const string& region_code,
PhoneNumber* number) const { … }
bool PhoneNumberUtil::GetExampleNumberForType(
const string& region_code,
PhoneNumberUtil::PhoneNumberType type,
PhoneNumber* number) const { … }
bool PhoneNumberUtil::GetExampleNumberForType(
PhoneNumberUtil::PhoneNumberType type,
PhoneNumber* number) const { … }
bool PhoneNumberUtil::GetExampleNumberForNonGeoEntity(
int country_calling_code, PhoneNumber* number) const { … }
PhoneNumberUtil::ErrorType PhoneNumberUtil::Parse(const string& number_to_parse,
const string& default_region,
PhoneNumber* number) const { … }
PhoneNumberUtil::ErrorType PhoneNumberUtil::ParseAndKeepRawInput(
const string& number_to_parse,
const string& default_region,
PhoneNumber* number) const { … }
bool PhoneNumberUtil::CheckRegionForParsing(
const string& number_to_parse,
const string& default_region) const { … }
void PhoneNumberUtil::BuildNationalNumberForParsing(
const string& number_to_parse, string* national_number) const { … }
PhoneNumberUtil::ErrorType PhoneNumberUtil::ParseHelper(
const string& number_to_parse,
const string& default_region,
bool keep_raw_input,
bool check_region,
PhoneNumber* phone_number) const { … }
void PhoneNumberUtil::ExtractPossibleNumber(const string& number,
string* extracted_number) const { … }
bool PhoneNumberUtil::IsPossibleNumber(const PhoneNumber& number) const { … }
bool PhoneNumberUtil::IsPossibleNumberForType(
const PhoneNumber& number, const PhoneNumberType type) const { … }
bool PhoneNumberUtil::IsPossibleNumberForString(
const string& number,
const string& region_dialing_from) const { … }
PhoneNumberUtil::ValidationResult PhoneNumberUtil::IsPossibleNumberWithReason(
const PhoneNumber& number) const { … }
PhoneNumberUtil::ValidationResult
PhoneNumberUtil::IsPossibleNumberForTypeWithReason(const PhoneNumber& number,
PhoneNumberType type) const { … }
bool PhoneNumberUtil::TruncateTooLongNumber(PhoneNumber* number) const { … }
PhoneNumberUtil::PhoneNumberType PhoneNumberUtil::GetNumberType(
const PhoneNumber& number) const { … }
bool PhoneNumberUtil::IsValidNumber(const PhoneNumber& number) const { … }
bool PhoneNumberUtil::IsValidNumberForRegion(const PhoneNumber& number,
const string& region_code) const { … }
bool PhoneNumberUtil::IsNumberGeographical(
const PhoneNumber& phone_number) const { … }
bool PhoneNumberUtil::IsNumberGeographical(
PhoneNumberType phone_number_type, int country_calling_code) const { … }
void PhoneNumberUtil::SetItalianLeadingZerosForPhoneNumber(
const string& national_number, PhoneNumber* phone_number) const { … }
bool PhoneNumberUtil::IsNumberMatchingDesc(
const string& national_number, const PhoneNumberDesc& number_desc) const { … }
PhoneNumberUtil::PhoneNumberType PhoneNumberUtil::GetNumberTypeHelper(
const string& national_number, const PhoneMetadata& metadata) const { … }
void PhoneNumberUtil::GetNationalSignificantNumber(
const PhoneNumber& number,
string* national_number) const { … }
int PhoneNumberUtil::GetLengthOfGeographicalAreaCode(
const PhoneNumber& number) const { … }
int PhoneNumberUtil::GetLengthOfNationalDestinationCode(
const PhoneNumber& number) const { … }
void PhoneNumberUtil::GetCountryMobileToken(int country_calling_code,
string* mobile_token) const { … }
void PhoneNumberUtil::NormalizeDigitsOnly(string* number) const { … }
void PhoneNumberUtil::NormalizeDiallableCharsOnly(string* number) const { … }
bool PhoneNumberUtil::IsAlphaNumber(const string& number) const { … }
void PhoneNumberUtil::ConvertAlphaCharactersInNumber(string* number) const { … }
void PhoneNumberUtil::Normalize(string* number) const { … }
bool PhoneNumberUtil::IsViablePhoneNumber(const string& number) const { … }
bool PhoneNumberUtil::ParsePrefixAsIdd(const RegExp& idd_pattern,
string* number) const { … }
PhoneNumber::CountryCodeSource
PhoneNumberUtil::MaybeStripInternationalPrefixAndNormalize(
const string& possible_idd_prefix,
string* number) const { … }
bool PhoneNumberUtil::MaybeStripNationalPrefixAndCarrierCode(
const PhoneMetadata& metadata,
string* number,
string* carrier_code) const { … }
bool PhoneNumberUtil::MaybeStripExtension(string* number, std::string* extension)
const { … }
int PhoneNumberUtil::ExtractCountryCode(string* national_number) const { … }
PhoneNumberUtil::ErrorType PhoneNumberUtil::MaybeExtractCountryCode(
const PhoneMetadata* default_region_metadata,
bool keep_raw_input,
string* national_number,
PhoneNumber* phone_number) const { … }
PhoneNumberUtil::MatchType PhoneNumberUtil::IsNumberMatch(
const PhoneNumber& first_number_in,
const PhoneNumber& second_number_in) const { … }
PhoneNumberUtil::MatchType PhoneNumberUtil::IsNumberMatchWithTwoStrings(
const string& first_number,
const string& second_number) const { … }
PhoneNumberUtil::MatchType PhoneNumberUtil::IsNumberMatchWithOneString(
const PhoneNumber& first_number,
const string& second_number) const { … }
AsYouTypeFormatter* PhoneNumberUtil::GetAsYouTypeFormatter(
const string& region_code) const { … }
bool PhoneNumberUtil::CanBeInternationallyDialled(
const PhoneNumber& number) const { … }
}
}