Clean up PackedPhoneNumber

This commit is contained in:
Ben Merritt 2019-08-01 23:00:08 -07:00
parent 55ef25ac07
commit 2e1dfefaed
No known key found for this signature in database
GPG Key ID: F8AD20ED4E6239B7
2 changed files with 7 additions and 6 deletions

View File

@ -3,7 +3,9 @@
using namespace google::protobuf; using namespace google::protobuf;
using namespace i18n::phonenumbers; using namespace i18n::phonenumbers;
const PhoneNumberUtil* const PhoneNumberTooLongException::phoneUtil = PhoneNumberUtil::GetInstance(); namespace {
const PhoneNumberUtil* phoneUtil = PhoneNumberUtil::GetInstance();
}
PhoneNumberTooLongException::PhoneNumberTooLongException(const PhoneNumber& number, const char* msg) : PhoneNumberTooLongException::PhoneNumberTooLongException(const PhoneNumber& number, const char* msg) :
std::runtime_error(msg), _number(number) {}; std::runtime_error(msg), _number(number) {};
@ -14,7 +16,8 @@ std::string PhoneNumberTooLongException::number_string() const {
return formatted; return formatted;
} }
PackedPhoneNumber::PackedPhoneNumber(i18n::phonenumbers::PhoneNumber number) { PackedPhoneNumber::PackedPhoneNumber(const i18n::phonenumbers::PhoneNumber& number) {
// TODO: check has_national_number(), etc?
uint32 country_code = number.country_code(); uint32 country_code = number.country_code();
if(country_code > max_country_code) { if(country_code > max_country_code) {
throw PhoneNumberTooLongException(number, "Country code is too long"); throw PhoneNumberTooLongException(number, "Country code is too long");

View File

@ -18,7 +18,7 @@ class PhoneNumberTooLongException : public std::runtime_error {
PhoneNumberTooLongException(const i18n::phonenumbers::PhoneNumber& number, const char* msg); PhoneNumberTooLongException(const i18n::phonenumbers::PhoneNumber& number, const char* msg);
/// Returns the original phone number object /// Returns the original phone number object
i18n::phonenumbers::PhoneNumber number() const { const i18n::phonenumbers::PhoneNumber& number() const {
return _number; return _number;
} }
@ -26,8 +26,6 @@ class PhoneNumberTooLongException : public std::runtime_error {
std::string number_string() const; std::string number_string() const;
private: private:
i18n::phonenumbers::PhoneNumber _number; i18n::phonenumbers::PhoneNumber _number;
static const i18n::phonenumbers::PhoneNumberUtil* const phoneUtil;
}; };
/** /**
@ -54,7 +52,7 @@ class PackedPhoneNumber {
static constexpr size_t leading_zeros_offset = country_code_offset + country_code_bits; static constexpr size_t leading_zeros_offset = country_code_offset + country_code_bits;
static constexpr size_t national_number_offset = leading_zeros_offset + leading_zeros_bits; static constexpr size_t national_number_offset = leading_zeros_offset + leading_zeros_bits;
PackedPhoneNumber(i18n::phonenumbers::PhoneNumber number); PackedPhoneNumber(const i18n::phonenumbers::PhoneNumber& number);
bool operator==(const PackedPhoneNumber other) const { bool operator==(const PackedPhoneNumber other) const {
return this->_data == other._data; return this->_data == other._data;