|
|
|
@ -32,7 +32,6 @@ |
|
|
|
|
|
|
|
#include "absl/container/node_hash_set.h" |
|
|
|
#include "absl/container/node_hash_map.h" |
|
|
|
#include "absl/strings/string_view.h" |
|
|
|
|
|
|
|
class TelephoneNumber; |
|
|
|
|
|
|
|
@ -40,6 +39,7 @@ namespace i18n { |
|
|
|
namespace phonenumbers { |
|
|
|
|
|
|
|
using google::protobuf::RepeatedPtrField; |
|
|
|
using std::string; |
|
|
|
|
|
|
|
class AsYouTypeFormatter; |
|
|
|
class Logger; |
|
|
|
@ -181,7 +181,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// @returns an unordered set of the two-letter region codes for every |
|
|
|
// geographical region the library supports |
|
|
|
void GetSupportedRegions( |
|
|
|
std::set<std::string>* regions) const; |
|
|
|
std::set<string>* regions) const; |
|
|
|
|
|
|
|
// Returns all global network calling codes the library has metadata for. |
|
|
|
// @returns an unordered set of the country calling codes for every |
|
|
|
@ -202,7 +202,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// |
|
|
|
// No types will be returned for invalid or unknown region codes. |
|
|
|
void GetSupportedTypesForRegion( |
|
|
|
const std::string& region_code, |
|
|
|
const string& region_code, |
|
|
|
std::set<PhoneNumberType>* types) const; |
|
|
|
|
|
|
|
// Returns the types for a country-code belonging to a non-geographical entity |
|
|
|
@ -232,26 +232,26 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// checks - to work out if this number is actually valid for a region, it |
|
|
|
// should be parsed and methods such as IsPossibleNumberWithReason or |
|
|
|
// IsValidNumber should be used. |
|
|
|
bool IsAlphaNumber(const std::string& number) const; |
|
|
|
bool IsAlphaNumber(const string& number) const; |
|
|
|
|
|
|
|
// Converts all alpha characters in a number to their respective digits on |
|
|
|
// a keypad, but retains existing formatting. |
|
|
|
void ConvertAlphaCharactersInNumber(std::string* number) const; |
|
|
|
void ConvertAlphaCharactersInNumber(string* number) const; |
|
|
|
|
|
|
|
// Normalizes a string of characters representing a phone number. This |
|
|
|
// converts wide-ascii and arabic-indic numerals to European numerals, and |
|
|
|
// strips punctuation and alpha characters. |
|
|
|
void NormalizeDigitsOnly(std::string* number) const; |
|
|
|
void NormalizeDigitsOnly(string* number) const; |
|
|
|
|
|
|
|
// Normalizes a string of characters representing a phone number. This strips |
|
|
|
// all characters which are not diallable on a mobile phone keypad (including |
|
|
|
// all non-ASCII digits). |
|
|
|
void NormalizeDiallableCharsOnly(std::string* number) const; |
|
|
|
void NormalizeDiallableCharsOnly(string* number) const; |
|
|
|
|
|
|
|
// Gets the national significant number of a phone number. Note a national |
|
|
|
// significant number doesn't contain a national prefix or any formatting. |
|
|
|
void GetNationalSignificantNumber( |
|
|
|
const PhoneNumber& number, std::string* national_significant_num) const; |
|
|
|
void GetNationalSignificantNumber(const PhoneNumber& number, |
|
|
|
string* national_significant_num) const; |
|
|
|
|
|
|
|
// Gets the length of the geographical area code from the PhoneNumber object |
|
|
|
// passed in, so that clients could use it to split a national significant |
|
|
|
@ -335,7 +335,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// before the area code when dialing a mobile number from that country from |
|
|
|
// abroad. |
|
|
|
void GetCountryMobileToken(int country_calling_code, |
|
|
|
std::string* mobile_token) const; |
|
|
|
string* mobile_token) const; |
|
|
|
|
|
|
|
// Formats a phone number in the specified format using default rules. Note |
|
|
|
// that this does not promise to produce a phone number that the user can |
|
|
|
@ -343,15 +343,17 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// INTERNATIONAL format depending on what the client asks for, we do not |
|
|
|
// currently support a more abbreviated format, such as for users in the |
|
|
|
// same area who could potentially dial the number without area code. |
|
|
|
void Format(const PhoneNumber& number, PhoneNumberFormat number_format, |
|
|
|
std::string* formatted_number) const; |
|
|
|
void Format(const PhoneNumber& number, |
|
|
|
PhoneNumberFormat number_format, |
|
|
|
string* formatted_number) const; |
|
|
|
|
|
|
|
// Formats a phone number in the specified format using client-defined |
|
|
|
// formatting rules. |
|
|
|
void FormatByPattern( |
|
|
|
const PhoneNumber& number, PhoneNumberFormat number_format, |
|
|
|
const PhoneNumber& number, |
|
|
|
PhoneNumberFormat number_format, |
|
|
|
const RepeatedPtrField<NumberFormat>& user_defined_formats, |
|
|
|
std::string* formatted_number) const; |
|
|
|
string* formatted_number) const; |
|
|
|
|
|
|
|
// Formats a phone number in national format for dialing using the carrier as |
|
|
|
// specified in the carrier_code. The carrier_code will always be used |
|
|
|
@ -359,8 +361,8 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// carrier code stored. If carrier_code contains an empty string, return the |
|
|
|
// number in national format without any carrier code. |
|
|
|
void FormatNationalNumberWithCarrierCode(const PhoneNumber& number, |
|
|
|
const std::string& carrier_code, |
|
|
|
std::string* formatted_number) const; |
|
|
|
const string& carrier_code, |
|
|
|
string* formatted_number) const; |
|
|
|
|
|
|
|
// Formats a phone number in national format for dialing using the carrier as |
|
|
|
// specified in the preferred_domestic_carrier_code field of the PhoneNumber |
|
|
|
@ -373,8 +375,9 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// in should take precedence over the number's preferred_domestic_carrier_code |
|
|
|
// when formatting. |
|
|
|
void FormatNationalNumberWithPreferredCarrierCode( |
|
|
|
const PhoneNumber& number, const std::string& fallback_carrier_code, |
|
|
|
std::string* formatted_number) const; |
|
|
|
const PhoneNumber& number, |
|
|
|
const string& fallback_carrier_code, |
|
|
|
string* formatted_number) const; |
|
|
|
|
|
|
|
// Returns a number formatted in such a way that it can be dialed from a |
|
|
|
// mobile phone in a specific region. If the number cannot be reached from |
|
|
|
@ -382,8 +385,9 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// outside of the country), the method returns an empty string. |
|
|
|
void FormatNumberForMobileDialing( |
|
|
|
const PhoneNumber& number, |
|
|
|
const std::string& region_calling_from, bool with_formatting, |
|
|
|
std::string* formatted_number) const; |
|
|
|
const string& region_calling_from, |
|
|
|
bool with_formatting, |
|
|
|
string* formatted_number) const; |
|
|
|
|
|
|
|
// Formats a phone number for out-of-country dialing purposes. |
|
|
|
// |
|
|
|
@ -393,8 +397,9 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// have multiple international prefixes, the number in its INTERNATIONAL |
|
|
|
// format will be returned instead. |
|
|
|
void FormatOutOfCountryCallingNumber( |
|
|
|
const PhoneNumber& number, const std::string& calling_from, |
|
|
|
std::string* formatted_number) const; |
|
|
|
const PhoneNumber& number, |
|
|
|
const string& calling_from, |
|
|
|
string* formatted_number) const; |
|
|
|
|
|
|
|
// Formats a phone number using the original phone number format (e.g. |
|
|
|
// INTERNATIONAL or NATIONAL) that the number is parsed from, provided that |
|
|
|
@ -406,8 +411,8 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// When the number is an invalid number, the method returns the raw input when |
|
|
|
// it is available. |
|
|
|
void FormatInOriginalFormat(const PhoneNumber& number, |
|
|
|
const std::string& region_calling_from, |
|
|
|
std::string* formatted_number) const; |
|
|
|
const string& region_calling_from, |
|
|
|
string* formatted_number) const; |
|
|
|
|
|
|
|
// Formats a phone number for out-of-country dialing purposes. |
|
|
|
// |
|
|
|
@ -427,8 +432,9 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// before these digits. Normally people group the first three digits together |
|
|
|
// so this is not a huge problem - and will be fixed if it proves to be so. |
|
|
|
void FormatOutOfCountryKeepingAlphaChars( |
|
|
|
const PhoneNumber& number, const std::string& calling_from, |
|
|
|
std::string* formatted_number) const; |
|
|
|
const PhoneNumber& number, |
|
|
|
const string& calling_from, |
|
|
|
string* formatted_number) const; |
|
|
|
|
|
|
|
// Attempts to extract a valid number from a phone number that is too long to |
|
|
|
// be valid, and resets the PhoneNumber object passed in to that valid |
|
|
|
@ -465,17 +471,17 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// since it has its own region code, "IM", which may be undesirable. |
|
|
|
bool IsValidNumberForRegion( |
|
|
|
const PhoneNumber& number, |
|
|
|
const std::string& region_code) const; |
|
|
|
const string& region_code) const; |
|
|
|
|
|
|
|
// Returns the region where a phone number is from. This could be used for |
|
|
|
// geocoding at the region level. Only guarantees correct results for valid, |
|
|
|
// full numbers (not short-codes, or invalid numbers). |
|
|
|
void GetRegionCodeForNumber(const PhoneNumber& number, |
|
|
|
std::string* region_code) const; |
|
|
|
string* region_code) const; |
|
|
|
|
|
|
|
// Returns the country calling code for a specific region. For example, |
|
|
|
// this would be 1 for the United States, and 64 for New Zealand. |
|
|
|
int GetCountryCodeForRegion(const std::string& region_code) const; |
|
|
|
int GetCountryCodeForRegion(const string& region_code) const; |
|
|
|
|
|
|
|
// Returns the region code that matches the specific country code. Note that |
|
|
|
// it is possible that several regions share the same country calling code |
|
|
|
@ -485,7 +491,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// (such as in the case of non-geographical calling codes like 800) the |
|
|
|
// RegionCode 001 will be returned (corresponding to the value for World in |
|
|
|
// the UN M.49 schema). |
|
|
|
void GetRegionCodeForCountryCode(int country_code, std::string* region_code) const; |
|
|
|
void GetRegionCodeForCountryCode(int country_code, string* region_code) const; |
|
|
|
|
|
|
|
// Populates a list with the region codes that match the specific country |
|
|
|
// calling code. For non-geographical country calling codes, the region code |
|
|
|
@ -493,20 +499,20 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// is left unchanged. |
|
|
|
void GetRegionCodesForCountryCallingCode( |
|
|
|
int country_calling_code, |
|
|
|
std::list<std::string>* region_codes) const; |
|
|
|
std::list<string>* region_codes) const; |
|
|
|
|
|
|
|
// Checks if this is a region under the North American Numbering Plan |
|
|
|
// Administration (NANPA). |
|
|
|
bool IsNANPACountry(const std::string& region_code) const; |
|
|
|
bool IsNANPACountry(const string& region_code) const; |
|
|
|
|
|
|
|
// Returns the national dialling prefix for a specific region. For example, |
|
|
|
// this would be 1 for the United States, and 0 for New Zealand. Set |
|
|
|
// strip_non_digits to true to strip symbols like "~" (which indicates a wait |
|
|
|
// for a dialling tone) from the prefix returned. If no national prefix is |
|
|
|
// present, we return an empty string. |
|
|
|
void GetNddPrefixForRegion(const std::string& region_code, |
|
|
|
void GetNddPrefixForRegion(const string& region_code, |
|
|
|
bool strip_non_digits, |
|
|
|
std::string* national_prefix) const; |
|
|
|
string* national_prefix) const; |
|
|
|
|
|
|
|
// Checks whether a phone number is a possible number. It provides a more |
|
|
|
// lenient check than IsValidNumber() in the following sense: |
|
|
|
@ -592,8 +598,8 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// as 253 0000, it could only be dialed from within a smaller area in the US |
|
|
|
// (Mountain View, CA, to be more specific). |
|
|
|
bool IsPossibleNumberForString( |
|
|
|
absl::string_view number, |
|
|
|
const std::string& region_dialing_from) const; |
|
|
|
const string& number, |
|
|
|
const string& region_dialing_from) const; |
|
|
|
|
|
|
|
// Returns true if the number can be dialled from outside the region, or |
|
|
|
// unknown. If the number can only be dialled from within the region, returns |
|
|
|
@ -617,7 +623,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// the region was unknown, or the region 001 is passed in. For 001 |
|
|
|
// (representing non-geographical numbers), call |
|
|
|
// GetExampleNumberForNonGeoEntity instead. |
|
|
|
bool GetExampleNumber(const std::string& region_code, |
|
|
|
bool GetExampleNumber(const string& region_code, |
|
|
|
PhoneNumber* number) const; |
|
|
|
|
|
|
|
// Gets an invalid number for the specified region. This is useful for |
|
|
|
@ -629,14 +635,14 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// |
|
|
|
// Returns false when an unsupported region or the region 001 (Earth) is |
|
|
|
// passed in. |
|
|
|
bool GetInvalidExampleNumber(const std::string& region_code, |
|
|
|
bool GetInvalidExampleNumber(const string& region_code, |
|
|
|
PhoneNumber* number) const; |
|
|
|
|
|
|
|
// Gets a valid number of the specified type for the specified region. |
|
|
|
// Returns false if the region was unknown or 001, or if no example number of |
|
|
|
// that type could be found. For 001 (representing non-geographical numbers), |
|
|
|
// call GetExampleNumberForNonGeoEntity instead. |
|
|
|
bool GetExampleNumberForType(const std::string& region_code, |
|
|
|
bool GetExampleNumberForType(const string& region_code, |
|
|
|
PhoneNumberType type, |
|
|
|
PhoneNumber* number) const; |
|
|
|
|
|
|
|
@ -691,15 +697,15 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// number (e.g.too few or too many digits) or if no default region was |
|
|
|
// supplied and the number is not in international format (does not start with |
|
|
|
// +). |
|
|
|
ErrorType Parse(absl::string_view number_to_parse, |
|
|
|
const std::string& default_region, |
|
|
|
ErrorType Parse(const string& number_to_parse, |
|
|
|
const string& default_region, |
|
|
|
PhoneNumber* number) const; |
|
|
|
// Parses a string and returns it in proto buffer format. This method differs |
|
|
|
// from Parse() in that it always populates the raw_input field of the |
|
|
|
// protocol buffer with number_to_parse as well as the country_code_source |
|
|
|
// field. |
|
|
|
ErrorType ParseAndKeepRawInput(absl::string_view number_to_parse, |
|
|
|
const std::string& default_region, |
|
|
|
ErrorType ParseAndKeepRawInput(const string& number_to_parse, |
|
|
|
const string& default_region, |
|
|
|
PhoneNumber* number) const; |
|
|
|
|
|
|
|
// Takes two phone numbers and compares them for equality. |
|
|
|
@ -723,8 +729,8 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// PhoneNumber secondNumber). No default region is known. |
|
|
|
// Returns INVALID_NUMBER if either number cannot be parsed into a phone |
|
|
|
// number. |
|
|
|
MatchType IsNumberMatchWithTwoStrings(absl::string_view first_number, |
|
|
|
absl::string_view second_number) const; |
|
|
|
MatchType IsNumberMatchWithTwoStrings(const string& first_number, |
|
|
|
const string& second_number) const; |
|
|
|
|
|
|
|
// Takes two phone numbers and compares them for equality. This is a |
|
|
|
// convenience wrapper for IsNumberMatch(PhoneNumber firstNumber, |
|
|
|
@ -732,7 +738,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// Returns INVALID_NUMBER if second_number cannot be parsed into a phone |
|
|
|
// number. |
|
|
|
MatchType IsNumberMatchWithOneString(const PhoneNumber& first_number, |
|
|
|
absl::string_view second_number) const; |
|
|
|
const string& second_number) const; |
|
|
|
|
|
|
|
// Overrides the default logging system. This takes ownership of the provided |
|
|
|
// logger. |
|
|
|
@ -743,7 +749,7 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
// numbers in the specific region "as you type". |
|
|
|
// The deletion of the returned instance is under the responsibility of the |
|
|
|
// caller. |
|
|
|
AsYouTypeFormatter* GetAsYouTypeFormatter(const std::string& region_code) const; |
|
|
|
AsYouTypeFormatter* GetAsYouTypeFormatter(const string& region_code) const; |
|
|
|
|
|
|
|
friend bool ConvertFromTelephoneNumberProto( |
|
|
|
const TelephoneNumber& proto_to_convert, |
|
|
|
@ -752,16 +758,16 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
TelephoneNumber* resulting_proto); |
|
|
|
|
|
|
|
protected: |
|
|
|
bool IsNumberMatchingDesc(const std::string& national_number, |
|
|
|
bool IsNumberMatchingDesc(const string& national_number, |
|
|
|
const PhoneNumberDesc& number_desc) const; |
|
|
|
|
|
|
|
PhoneNumberUtil::PhoneNumberType GetNumberTypeHelper( |
|
|
|
const std::string& national_number, const PhoneMetadata& metadata) const; |
|
|
|
const string& national_number, const PhoneMetadata& metadata) const; |
|
|
|
|
|
|
|
private: |
|
|
|
scoped_ptr<Logger> logger_; |
|
|
|
|
|
|
|
typedef std::pair<int, std::list<std::string>*> IntRegionsPair; |
|
|
|
typedef std::pair<int, std::list<string>*> IntRegionsPair; |
|
|
|
|
|
|
|
// The minimum and maximum length of the national significant number. |
|
|
|
static const size_t kMinLengthForNsn = 2; |
|
|
|
@ -806,11 +812,11 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
country_calling_code_to_region_code_map_; |
|
|
|
|
|
|
|
// The set of regions that share country calling code 1. |
|
|
|
scoped_ptr<absl::node_hash_set<std::string> > nanpa_regions_; |
|
|
|
scoped_ptr<absl::node_hash_set<string> > nanpa_regions_; |
|
|
|
static const int kNanpaCountryCode = 1; |
|
|
|
|
|
|
|
// A mapping from a region code to a PhoneMetadata for that region. |
|
|
|
scoped_ptr<absl::node_hash_map<std::string, PhoneMetadata> > region_to_metadata_map_; |
|
|
|
scoped_ptr<absl::node_hash_map<string, PhoneMetadata> > region_to_metadata_map_; |
|
|
|
|
|
|
|
// A mapping from a country calling code for a non-geographical entity to the |
|
|
|
// PhoneMetadata for that country calling code. Examples of the country |
|
|
|
@ -823,144 +829,154 @@ class PhoneNumberUtil : public Singleton<PhoneNumberUtil> { |
|
|
|
|
|
|
|
// Returns a regular expression for the possible extensions that may be found |
|
|
|
// in a number, for use when matching. |
|
|
|
const std::string& GetExtnPatternsForMatching() const; |
|
|
|
const string& GetExtnPatternsForMatching() const; |
|
|
|
|
|
|
|
// Checks if a number matches the plus chars pattern. |
|
|
|
bool StartsWithPlusCharsPattern(const std::string& number) const; |
|
|
|
bool StartsWithPlusCharsPattern(const string& number) const; |
|
|
|
|
|
|
|
void SetItalianLeadingZerosForPhoneNumber(const std::string& national_number, |
|
|
|
PhoneNumber* phone_number) const; |
|
|
|
void SetItalianLeadingZerosForPhoneNumber( |
|
|
|
const string& national_number, PhoneNumber* phone_number) const; |
|
|
|
|
|
|
|
// Checks whether a string contains only valid digits. |
|
|
|
bool ContainsOnlyValidDigits(const std::string& s) const; |
|
|
|
bool ContainsOnlyValidDigits(const string& s) const; |
|
|
|
|
|
|
|
// Checks if a format is eligible to be used by the AsYouTypeFormatter. This |
|
|
|
// method is here rather than in asyoutypeformatter.h since it depends on the |
|
|
|
// valid punctuation declared by the phone number util. |
|
|
|
bool IsFormatEligibleForAsYouTypeFormatter(const std::string& format) const; |
|
|
|
bool IsFormatEligibleForAsYouTypeFormatter(const string& format) const; |
|
|
|
|
|
|
|
// Helper function to check if the national prefix formatting rule has the |
|
|
|
// first group only, i.e., does not start with the national prefix. |
|
|
|
bool FormattingRuleHasFirstGroupOnly( |
|
|
|
const std::string& national_prefix_formatting_rule) const; |
|
|
|
const string& national_prefix_formatting_rule) const; |
|
|
|
|
|
|
|
// Trims unwanted end characters from a phone number string. |
|
|
|
void TrimUnwantedEndChars(std::string* number) const; |
|
|
|
void TrimUnwantedEndChars(string* number) const; |
|
|
|
|
|
|
|
// Helper function to check region code is not unknown or null. |
|
|
|
bool IsValidRegionCode(const std::string& region_code) const; |
|
|
|
bool IsValidRegionCode(const string& region_code) const; |
|
|
|
|
|
|
|
// Helper function to check the country calling code is valid. |
|
|
|
bool HasValidCountryCallingCode(int country_calling_code) const; |
|
|
|
|
|
|
|
const i18n::phonenumbers::PhoneMetadata* GetMetadataForRegion( |
|
|
|
const std::string& region_code) const; |
|
|
|
const string& region_code) const; |
|
|
|
|
|
|
|
const i18n::phonenumbers::PhoneMetadata* GetMetadataForNonGeographicalRegion( |
|
|
|
int country_calling_code) const; |
|
|
|
|
|
|
|
const i18n::phonenumbers::PhoneMetadata* GetMetadataForRegionOrCallingCode( |
|
|
|
int country_calling_code, |
|
|
|
const std::string& region_code) const; |
|
|
|
const string& region_code) const; |
|
|
|
|
|
|
|
// As per GetCountryCodeForRegion, but assumes the validity of the region_code |
|
|
|
// has already been checked. |
|
|
|
int GetCountryCodeForValidRegion(const std::string& region_code) const; |
|
|
|
int GetCountryCodeForValidRegion(const string& region_code) const; |
|
|
|
|
|
|
|
const NumberFormat* ChooseFormattingPatternForNumber( |
|
|
|
const RepeatedPtrField<NumberFormat>& available_formats, |
|
|
|
const std::string& national_number) const; |
|
|
|
const string& national_number) const; |
|
|
|
|
|
|
|
void FormatNsnUsingPatternWithCarrier( |
|
|
|
const std::string& national_number, |
|
|
|
const string& national_number, |
|
|
|
const NumberFormat& formatting_pattern, |
|
|
|
PhoneNumberUtil::PhoneNumberFormat number_format, |
|
|
|
const std::string& carrier_code, std::string* formatted_number) const; |
|
|
|
const string& carrier_code, |
|
|
|
string* formatted_number) const; |
|
|
|
|
|
|
|
void FormatNsnUsingPattern(const std::string& national_number, |
|
|
|
const NumberFormat& formatting_pattern, |
|
|
|
PhoneNumberUtil::PhoneNumberFormat number_format, |
|
|
|
std::string* formatted_number) const; |
|
|
|
void FormatNsnUsingPattern( |
|
|
|
const string& national_number, |
|
|
|
const NumberFormat& formatting_pattern, |
|
|
|
PhoneNumberUtil::PhoneNumberFormat number_format, |
|
|
|
string* formatted_number) const; |
|
|
|
|
|
|
|
// Check if raw_input, which is assumed to be in the national format, has a |
|
|
|
// national prefix. The national prefix is assumed to be in digits-only form. |
|
|
|
bool RawInputContainsNationalPrefix( |
|
|
|
const std::string& raw_input, const std::string& national_prefix, |
|
|
|
const std::string& region_code) const; |
|
|
|
const string& raw_input, |
|
|
|
const string& national_prefix, |
|
|
|
const string& region_code) const; |
|
|
|
|
|
|
|
bool HasFormattingPatternForNumber(const PhoneNumber& number) const; |
|
|
|
|
|
|
|
// Simple wrapper of FormatNsnWithCarrier for the common case of |
|
|
|
// no carrier code. |
|
|
|
void FormatNsn(const std::string& number, const PhoneMetadata& metadata, |
|
|
|
void FormatNsn(const string& number, |
|
|
|
const PhoneMetadata& metadata, |
|
|
|
PhoneNumberFormat number_format, |
|
|
|
std::string* formatted_number) const; |
|
|
|
string* formatted_number) const; |
|
|
|
|
|
|
|
void FormatNsnWithCarrier(const std::string& number, |
|
|
|
void FormatNsnWithCarrier(const string& number, |
|
|
|
const PhoneMetadata& metadata, |
|
|
|
PhoneNumberFormat number_format, |
|
|
|
const std::string& carrier_code, |
|
|
|
std::string* formatted_number) const; |
|
|
|
const string& carrier_code, |
|
|
|
string* formatted_number) const; |
|
|
|
|
|
|
|
void MaybeAppendFormattedExtension(const PhoneNumber& number, |
|
|
|
const PhoneMetadata& metadata, |
|
|
|
PhoneNumberFormat number_format, |
|
|
|
std::string* extension) const; |
|
|
|
void MaybeAppendFormattedExtension( |
|
|
|
const PhoneNumber& number, |
|
|
|
const PhoneMetadata& metadata, |
|
|
|
PhoneNumberFormat number_format, |
|
|
|
string* extension) const; |
|
|
|
|
|
|
|
void GetRegionCodeForNumberFromRegionList( |
|
|
|
const PhoneNumber& number, |
|
|
|
const std::list<std::string>& region_codes, |
|
|
|
std::string* region_code) const; |
|
|
|
const std::list<string>& region_codes, |
|
|
|
string* region_code) const; |
|
|
|
|
|
|
|
// Strips the IDD from the start of the number if present. Helper function |
|
|
|
// used by MaybeStripInternationalPrefixAndNormalize. |
|
|
|
bool ParsePrefixAsIdd(const RegExp& idd_pattern, std::string* number) const; |
|
|
|
bool ParsePrefixAsIdd(const RegExp& idd_pattern, string* number) const; |
|
|
|
|
|
|
|
void Normalize(std::string* number) const; |
|
|
|
void Normalize(string* number) const; |
|
|
|
|
|
|
|
PhoneNumber::CountryCodeSource MaybeStripInternationalPrefixAndNormalize( |
|
|
|
const std::string& possible_idd_prefix, std::string* number) const; |
|
|
|
const string& possible_idd_prefix, |
|
|
|
string* number) const; |
|
|
|
|
|
|
|
bool MaybeStripNationalPrefixAndCarrierCode(const PhoneMetadata& metadata, |
|
|
|
std::string* number, |
|
|
|
std::string* carrier_code) const; |
|
|
|
bool MaybeStripNationalPrefixAndCarrierCode( |
|
|
|
const PhoneMetadata& metadata, |
|
|
|
string* number, |
|
|
|
string* carrier_code) const; |
|
|
|
|
|
|
|
void ExtractPossibleNumber(absl::string_view number, |
|
|
|
std::string* extracted_number) const; |
|
|
|
void ExtractPossibleNumber(const string& number, |
|
|
|
string* extracted_number) const; |
|
|
|
|
|
|
|
bool IsViablePhoneNumber(const std::string& number) const; |
|
|
|
bool IsViablePhoneNumber(const string& number) const; |
|
|
|
|
|
|
|
bool MaybeStripExtension(std::string* number, std::string* extension) const; |
|
|
|
bool MaybeStripExtension(string* number, string* extension) const; |
|
|
|
|
|
|
|
int ExtractCountryCode(std::string* national_number) const; |
|
|
|
int ExtractCountryCode(string* national_number) const; |
|
|
|
ErrorType MaybeExtractCountryCode( |
|
|
|
const PhoneMetadata* default_region_metadata, bool keepRawInput, |
|
|
|
std::string* national_number, PhoneNumber* phone_number) const; |
|
|
|
|
|
|
|
bool CheckRegionForParsing(const std::string& number_to_parse, |
|
|
|
const std::string& default_region) const; |
|
|
|
|
|
|
|
ErrorType ParseHelper(absl::string_view number_to_parse, |
|
|
|
const std::string& default_region, |
|
|
|
bool keep_raw_input, bool check_region, |
|
|
|
const PhoneMetadata* default_region_metadata, |
|
|
|
bool keepRawInput, |
|
|
|
string* national_number, |
|
|
|
PhoneNumber* phone_number) const; |
|
|
|
|
|
|
|
bool CheckRegionForParsing( |
|
|
|
const string& number_to_parse, |
|
|
|
const string& default_region) const; |
|
|
|
|
|
|
|
ErrorType ParseHelper(const string& number_to_parse, |
|
|
|
const string& default_region, |
|
|
|
bool keep_raw_input, |
|
|
|
bool check_region, |
|
|
|
PhoneNumber* phone_number) const; |
|
|
|
|
|
|
|
absl::optional<absl::string_view> ExtractPhoneContext( |
|
|
|
absl::string_view number_to_extract_from, |
|
|
|
std::size_t index_of_phone_context) const; |
|
|
|
absl::optional<string> ExtractPhoneContext( |
|
|
|
const string& number_to_extract_from, |
|
|
|
size_t index_of_phone_context) const; |
|
|
|
|
|
|
|
bool IsPhoneContextValid( |
|
|
|
absl::optional<absl::string_view> phone_context) const; |
|
|
|
bool IsPhoneContextValid(absl::optional<string> phone_context) const; |
|
|
|
|
|
|
|
ErrorType BuildNationalNumberForParsing(absl::string_view number_to_parse, |
|
|
|
std::string* national_number) const; |
|
|
|
ErrorType BuildNationalNumberForParsing(const string& number_to_parse, |
|
|
|
string* national_number) const; |
|
|
|
|
|
|
|
bool IsShorterThanPossibleNormalNumber(const PhoneMetadata* country_metadata, |
|
|
|
const std::string& number) const; |
|
|
|
const string& number) const; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} // namespace phonenumbers |
|
|
|
} // namespace i18n |
|
|
|
|
|
|
|
#endif // I18N_PHONENUMBERS_PHONENUMBERUTIL_H_ |
|
|
|
#endif // I18N_PHONENUMBERS_PHONENUMBERUTIL_H_ |