Browse Source

Openvcdiff stringviews (#3620)

* Qualify std::string and change some string args to absl::string_view

* Update pending_code_changes.txt to describe code changes
pull/3624/head
openvcdiff 1 year ago
committed by GitHub
parent
commit
e85a2ff1a7
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
5 changed files with 348 additions and 376 deletions
  1. +225
    -244
      cpp/src/phonenumbers/phonenumberutil.cc
  2. +112
    -128
      cpp/src/phonenumbers/phonenumberutil.h
  3. +4
    -0
      cpp/src/phonenumbers/stringutil.cc
  4. +4
    -3
      cpp/src/phonenumbers/stringutil.h
  5. +3
    -1
      pending_code_changes.txt

+ 225
- 244
cpp/src/phonenumbers/phonenumberutil.cc
File diff suppressed because it is too large
View File


+ 112
- 128
cpp/src/phonenumbers/phonenumberutil.h View File

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


+ 4
- 0
cpp/src/phonenumbers/stringutil.cc View File

@ -134,6 +134,10 @@ StringHolder::StringHolder(uint64 n)
: absl::AlphaNum(n) : absl::AlphaNum(n)
{} {}
StringHolder::StringHolder(absl::string_view sv)
: absl::AlphaNum(sv)
{}
StringHolder::~StringHolder() {} StringHolder::~StringHolder() {}
// StrCat // StrCat


+ 4
- 3
cpp/src/phonenumbers/stringutil.h View File

@ -80,9 +80,10 @@ int GlobalReplaceSubstring(const string& substring, const string& replacement,
class StringHolder: public absl::AlphaNum { class StringHolder: public absl::AlphaNum {
public: public:
// Don't make the constructors explicit to make the StrCat usage convenient. // Don't make the constructors explicit to make the StrCat usage convenient.
StringHolder(const string& s); // NOLINT(runtime/explicit)
StringHolder(const char* s); // NOLINT(runtime/explicit)
StringHolder(uint64_t n); // NOLINT(runtime/explicit)
StringHolder(const string& s); // NOLINT(runtime/explicit)
StringHolder(const char* s); // NOLINT(runtime/explicit)
StringHolder(uint64_t n); // NOLINT(runtime/explicit)
StringHolder(absl::string_view sv); // NOLINT(runtime/explicit)
~StringHolder(); ~StringHolder();
const absl::string_view GetString() const { const absl::string_view GetString() const {


+ 3
- 1
pending_code_changes.txt View File

@ -1 +1,3 @@
Code changes:
- Added the std:: qualifier to string throughout phonenumberutil.
- Changed several std::string parameters to absl::string_view.

Loading…
Cancel
Save