From 8505b3840dd66f9e6e9fcdfbd4db79187b753223 Mon Sep 17 00:00:00 2001 From: Philip Liard Date: Mon, 28 Feb 2011 13:29:25 +0000 Subject: [PATCH] Update phonenumber proto and logging. --- cpp/CMakeLists.txt | 34 +++++++++++++++++++++++++++++++++- cpp/src/default_logger.cc | 10 +++++----- cpp/src/default_logger.h | 12 ++++++------ cpp/src/phonenumber.proto | 12 ++++++++++++ 4 files changed, 56 insertions(+), 12 deletions(-) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index d79af6b71..3c5db657d 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Author: Philippe Liard + + cmake_minimum_required (VERSION 2.8) project (libphonenumber) @@ -61,6 +64,25 @@ if (PROTOC STREQUAL "PROTOC-NOTFOUND") "Please read README.") endif () + +# Find ICU +find_path (ICU_INCLUDE_DIR unicode/unistr.h unicode/normlzr.h) + +if (ICU_INCLUDE_DIR STREQUAL "ICU_INCLUDE_DIR-NOTFOUND") + message (FATAL_ERROR + "Can't find ICU headers. Please read README.") +endif () + +include_directories (${ICU_INCLUDE_DIR}) + +find_library (ICU_LIB icui18n) + +if (ICU_LIB STREQUAL "ICU_LIB-NOTFOUND") + message (FATAL_ERROR + "Can't find ICU library. Please read README.") +endif () + + # Add protoc (Protocol Buffers compiler) target set ( PROTOBUF_SOURCES "${CMAKE_SOURCE_DIR}/src/phonemetadata.proto" @@ -95,12 +117,20 @@ set ( SOURCES "src/base/at_exit.cc" "src/base/lazy_instance.cc" + "src/base/string_piece.cc" "src/base/synchronization/lock.cc" "src/base/threading/thread_restrictions.cc" + "src/default_logger.cc" + "src/logger_adapter.cc" + "src/metadata.cc" # Generated by src/embed_binary_data.sh + "src/phonemetadata.pb.cc" # Generated by Protocol Buffers + "src/phonenumber.pb.cc" # Generated by Protocol Buffers "src/phonenumberutil.cc" "src/re2_cache.cc" "src/stringutil.cc" "src/utf/rune.c" + "src/utf/unicodetext.cc" + "src/utf/unilib.cc" ) if (UNIX) @@ -141,11 +171,12 @@ endif () include_directories ("src") +include_directories (".") add_library (phonenumber STATIC ${SOURCES}) add_dependencies (phonenumber generate-sources) -target_link_libraries (phonenumber re2) +target_link_libraries (phonenumber re2 protobuf icui18n) # Tests @@ -154,6 +185,7 @@ set (TEST_SOURCES "src/re2_cache_test.cc" "src/run_tests.cc" "src/stringutil_test.cc" + "src/test_metadata.cc" ) add_executable (libphonenumber_test ${TEST_SOURCES}) diff --git a/cpp/src/default_logger.cc b/cpp/src/default_logger.cc index a11679cb4..11eb59f04 100644 --- a/cpp/src/default_logger.cc +++ b/cpp/src/default_logger.cc @@ -30,31 +30,31 @@ DefaultLogger::DefaultLogger(LogLevel level) : level_(level) {} DefaultLogger::~DefaultLogger() {} void DefaultLogger::Fatal(const string& msg) const { - if (level_ >= FATAL) { + if (level_ >= LOG_FATAL) { cerr << "FATAL libphonenumber " << msg << endl; } } void DefaultLogger::Error(const string& msg) const { - if (level_ >= ERROR) { + if (level_ >= LOG_ERROR) { cerr << "ERROR libphonenumber " << msg << endl; } } void DefaultLogger::Warning(const string& msg) const { - if (level_ >= WARNING) { + if (level_ >= LOG_WARNING) { cerr << "WARNING libphonenumber " << msg << endl; } } void DefaultLogger::Info(const string& msg) const { - if (level_ >= INFO) { + if (level_ >= LOG_INFO) { cout << "INFO libphonenumber " << msg << endl; } } void DefaultLogger::Debug(const string& msg) const { - if (level_ >= DEBUG) { + if (level_ >= LOG_DEBUG) { cout << "DEBUG libphonenumber " << msg << endl; } } diff --git a/cpp/src/default_logger.h b/cpp/src/default_logger.h index 917e6ba99..d1ebc1f10 100644 --- a/cpp/src/default_logger.h +++ b/cpp/src/default_logger.h @@ -23,18 +23,18 @@ namespace i18n { namespace phonenumbers { enum LogLevel { - FATAL, - ERROR, - WARNING, - INFO, - DEBUG, + LOG_FATAL, + LOG_ERROR, + LOG_WARNING, + LOG_INFO, + LOG_DEBUG, }; class DefaultLogger : public LoggerAdapter { public: virtual ~DefaultLogger(); - DefaultLogger(LogLevel level = WARNING); + DefaultLogger(LogLevel level = LOG_WARNING); virtual void Fatal(const string& msg) const; diff --git a/cpp/src/phonenumber.proto b/cpp/src/phonenumber.proto index bee6ba21e..291f97d8f 100644 --- a/cpp/src/phonenumber.proto +++ b/cpp/src/phonenumber.proto @@ -54,6 +54,10 @@ message PhoneNumber { // necessary automatically. optional bool italian_leading_zero = 4; +// The next few fields are non-essential fields for a phone number. They retain extra information +// about the form the phone number was in when it was provided to us to parse. They can be safely +// ignored by most clients. + // This field is used to store the raw input string containing phone numbers before it was // canonicalized by the library. For example, it could be used to store alphanumerical numbers // such as "1-800-GOOG-411". @@ -83,6 +87,14 @@ message PhoneNumber { // The source from which the country_code is derived. optional CountryCodeSource country_code_source = 6; + +// The carrier selection code that is preferred when calling this phone number domestically. This +// also includes codes that need to be dialed in some countries when calling from landlines to +// mobiles or vice versa. For example, in Columbia, a "3" needs to be dialed before the phone number +// itself when calling from a mobile phone to a domestic landline phone and vice versa. +// +// Note this is the "preferred" code, which means other codes may work as well. + optional string preferred_domestic_carrier_code = 7; } // Examples