diff options
Diffstat (limited to 'third_party/libphonenumber/cpp')
-rw-r--r-- | third_party/libphonenumber/cpp/src/phonenumberutil.cc | 40 | ||||
-rw-r--r-- | third_party/libphonenumber/cpp/src/phonenumberutil.h | 5 |
2 files changed, 25 insertions, 20 deletions
diff --git a/third_party/libphonenumber/cpp/src/phonenumberutil.cc b/third_party/libphonenumber/cpp/src/phonenumberutil.cc index b0201f2..28fbd43 100644 --- a/third_party/libphonenumber/cpp/src/phonenumberutil.cc +++ b/third_party/libphonenumber/cpp/src/phonenumberutil.cc @@ -1765,30 +1765,32 @@ void PhoneNumberUtil::NormalizeDigitsOnly(string* number) { UParseError error; icu::ErrorCode status; - scoped_ptr<icu::Transliterator> transliterator( - icu::Transliterator::createFromRules( - "NormalizeDecimalDigits", - "[[:nv=0:]-[0]-[:^nt=de:]]>0;" - "[[:nv=1:]-[1]-[:^nt=de:]]>1;" - "[[:nv=2:]-[2]-[:^nt=de:]]>2;" - "[[:nv=3:]-[3]-[:^nt=de:]]>3;" - "[[:nv=4:]-[4]-[:^nt=de:]]>4;" - "[[:nv=5:]-[5]-[:^nt=de:]]>5;" - "[[:nv=6:]-[6]-[:^nt=de:]]>6;" - "[[:nv=7:]-[7]-[:^nt=de:]]>7;" - "[[:nv=8:]-[8]-[:^nt=de:]]>8;" - "[[:nv=9:]-[9]-[:^nt=de:]]>9;", - UTRANS_FORWARD, - error, - status - ) - ); + if (!GetInstance()->transliterator_.get()) { + GetInstance()->transliterator_.reset( + icu::Transliterator::createFromRules( + "NormalizeDecimalDigits", + "[[:nv=0:]-[0]-[:^nt=de:]]>0;" + "[[:nv=1:]-[1]-[:^nt=de:]]>1;" + "[[:nv=2:]-[2]-[:^nt=de:]]>2;" + "[[:nv=3:]-[3]-[:^nt=de:]]>3;" + "[[:nv=4:]-[4]-[:^nt=de:]]>4;" + "[[:nv=5:]-[5]-[:^nt=de:]]>5;" + "[[:nv=6:]-[6]-[:^nt=de:]]>6;" + "[[:nv=7:]-[7]-[:^nt=de:]]>7;" + "[[:nv=8:]-[8]-[:^nt=de:]]>8;" + "[[:nv=9:]-[9]-[:^nt=de:]]>9;", + UTRANS_FORWARD, + error, + status + ) + ); + } if (!status.isSuccess()) { logger->Error("Error creating ICU Transliterator"); return; } icu::UnicodeString utf16(icu::UnicodeString::fromUTF8(number->c_str())); - transliterator->transliterate(utf16); + GetInstance()->transliterator_->transliterate(utf16); number->clear(); utf16.toUTF8String(*number); } diff --git a/third_party/libphonenumber/cpp/src/phonenumberutil.h b/third_party/libphonenumber/cpp/src/phonenumberutil.h index 6a766df..43137a0 100644 --- a/third_party/libphonenumber/cpp/src/phonenumberutil.h +++ b/third_party/libphonenumber/cpp/src/phonenumberutil.h @@ -26,6 +26,7 @@ #include <string> #include <utility> #include <vector> +#include <unicode/translit.h> #include "base/scoped_ptr.h" #include "base/singleton.h" @@ -57,7 +58,7 @@ class PhoneNumberUtil { public: // INTERNATIONAL and NATIONAL formats are consistent with the definition // in ITU-T Recommendation E. 123. For example, the number of the Google - // Zürich office will be written as "+41 44 668 1800" in INTERNATIONAL + // Zurich office will be written as "+41 44 668 1800" in INTERNATIONAL // format, and as "044 668 1800" in NATIONAL format. E164 format is as per // INTERNATIONAL format but with no formatting applied e.g. +41446681800. // RFC3966 is as per INTERNATIONAL format, but with all spaces and other @@ -669,6 +670,8 @@ class PhoneNumberUtil { bool check_region, PhoneNumber* phone_number) const; + scoped_ptr<icu::Transliterator> transliterator_; + DISALLOW_COPY_AND_ASSIGN(PhoneNumberUtil); }; |