summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphilip.liard@gmail.com <philip.liard@gmail.com@ee073f10-1060-11df-b6a4-87a95322a99c>2013-05-07 12:59:58 +0000
committerphilip.liard@gmail.com <philip.liard@gmail.com@ee073f10-1060-11df-b6a4-87a95322a99c>2013-05-07 12:59:58 +0000
commit58f5155fbb4f056219281b59651435a7c0a26e67 (patch)
treee4708e69ca256a26c344ac524963563a18838b96
parent4b697b915e27c9b8df3ac42d9cbb2751852f4ea1 (diff)
downloadandroid_external_libphonenumbergoogle-58f5155fbb4f056219281b59651435a7c0a26e67.tar.gz
android_external_libphonenumbergoogle-58f5155fbb4f056219281b59651435a7c0a26e67.tar.bz2
android_external_libphonenumbergoogle-58f5155fbb4f056219281b59651435a7c0a26e67.zip
CPP: Make use of alternate format controlled at compile time.
This is needed to use a recent revision of libphonenumber in Chromium without building with alternate formats. BUG=http://crbug.com/236272 R=jia.shao.peng@gmail.com Review URL: https://codereview.appspot.com/9215046 git-svn-id: http://libphonenumber.googlecode.com/svn/trunk@572 ee073f10-1060-11df-b6a4-87a95322a99c
-rw-r--r--cpp/CMakeLists.txt35
-rw-r--r--cpp/README16
-rw-r--r--cpp/src/phonenumbers/phonenumbermatcher.cc5
3 files changed, 38 insertions, 18 deletions
diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index d8c1382..91f4e0c 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -70,12 +70,17 @@ endfunction (find_required_program)
# Options that can be passed to CMake using 'cmake -DKEY=VALUE'.
option ("BUILD_GEOCODER" "Build the offline phone number geocoder" "ON")
+option ("USE_ALTERNATE_FORMATS" "Use alternate formats" "ON")
option ("USE_BOOST" "Use Boost" "ON")
option ("USE_ICU_REGEXP" "Use ICU regexp engine" "ON")
option ("USE_LITE_METADATA" "Use lite metadata" "OFF")
option ("USE_RE2" "Use RE2" "OFF")
option ("USE_STD_MAP" "Force the use of std::map" "OFF")
+if (${USE_ALTERNATE_FORMATS} STREQUAL "ON")
+ add_definitions ("-DI18N_PHONENUMBERS_USE_ALTERNATE_FORMATS")
+endif ()
+
# Find all the required libraries and programs.
if (${USE_BOOST} STREQUAL "ON")
add_definitions ("-DI18N_PHONENUMBERS_USE_BOOST")
@@ -223,9 +228,11 @@ if (${USE_ICU_REGEXP} STREQUAL "ON")
add_definitions ("-DI18N_PHONENUMBERS_USE_ICU_REGEXP")
list (APPEND SOURCES "src/phonenumbers/regexp_adapter_icu.cc")
# The phone number matcher needs ICU.
- list (APPEND SOURCES "src/phonenumbers/alternate_format.cc")
list (APPEND SOURCES "src/phonenumbers/phonenumbermatch.cc")
list (APPEND SOURCES "src/phonenumbers/phonenumbermatcher.cc")
+ if (${USE_ALTERNATE_FORMATS} STREQUAL "ON")
+ list (APPEND SOURCES "src/phonenumbers/alternate_format.cc")
+ endif ()
endif ()
# Library sources excluding the metadata files, since special metadata is used
@@ -298,14 +305,16 @@ add_metadata_gen_target (
list (APPEND TESTING_LIBRARY_SOURCES "src/phonenumbers/test_metadata.cc")
if (${USE_ICU_REGEXP} STREQUAL "ON")
- # Add alternate format metadata generation for the phone number matcher
- set (ALT_FORMAT_METADATA_TARGET "generate-alt-format-metadata")
- add_metadata_gen_target (
- ${ALT_FORMAT_METADATA_TARGET}
- "${RESOURCES_DIR}/PhoneNumberAlternateFormats.xml"
- "alternate_format"
- "alternate_format"
- )
+ if (${USE_ALTERNATE_FORMATS} STREQUAL "ON")
+ # Add alternate format metadata generation for the phone number matcher.
+ set (ALT_FORMAT_METADATA_TARGET "generate-alt-format-metadata")
+ add_metadata_gen_target (
+ ${ALT_FORMAT_METADATA_TARGET}
+ "${RESOURCES_DIR}/PhoneNumberAlternateFormats.xml"
+ "alternate_format"
+ "alternate_format"
+ )
+ endif ()
endif ()
if (NOT WIN32)
@@ -317,7 +326,9 @@ include_directories ("src")
# Build a static library (without -fPIC).
add_library (phonenumber STATIC ${SOURCES})
if (${USE_ICU_REGEXP} STREQUAL "ON")
- add_dependencies (phonenumber ${ALT_FORMAT_METADATA_TARGET})
+ if (${USE_ALTERNATE_FORMATS} STREQUAL "ON")
+ add_dependencies (phonenumber ${ALT_FORMAT_METADATA_TARGET})
+ endif ()
endif ()
if (${BUILD_GEOCODER} STREQUAL "ON")
@@ -349,7 +360,9 @@ endif ()
if (BUILD_SHARED_LIB)
add_library (phonenumber-shared SHARED ${SOURCES})
if (${USE_ICU_REGEXP} STREQUAL "ON")
- add_dependencies (phonenumber ${ALT_FORMAT_METADATA_TARGET})
+ if (${USE_ALTERNATE_FORMATS} STREQUAL "ON")
+ add_dependencies (phonenumber ${ALT_FORMAT_METADATA_TARGET})
+ endif ()
endif ()
set_target_properties (phonenumber-shared
PROPERTIES
diff --git a/cpp/README b/cpp/README
index 1cee32c..99e0a5c 100644
--- a/cpp/README
+++ b/cpp/README
@@ -232,10 +232,12 @@ Supported build parameters
Build parameters can be specified invoking CMake with '-DKEY=VALUE' or using a
CMake user interface (ccmake or cmake-gui).
- USE_BOOST = ON | OFF [ON] -- Use Boost. This is only needed in
- multi-threaded environments.
- USE_ICU_REGEXP = ON | OFF [ON] -- Use ICU regexp engine.
- USE_LITE_METADATA = ON | OFF [OFF] -- Generates smaller metadata that doesn't
- include example numbers.
- USE_RE2 = ON | OFF [OFF] -- Use RE2.
- USE_STD_MAP = ON | OFF [OFF] -- Force the use of std::map.
+ USE_ALTERNATE_FORMATS = ON | OFF [ON] -- Use alternate formats for the phone
+ number matcher.
+ USE_BOOST = ON | OFF [ON] -- Use Boost. This is only needed in
+ multi-threaded environments.
+ USE_ICU_REGEXP = ON | OFF [ON] -- Use ICU regexp engine.
+ USE_LITE_METADATA = ON | OFF [OFF] -- Generates smaller metadata that
+ doesn't include example numbers.
+ USE_RE2 = ON | OFF [OFF] -- Use RE2.
+ USE_STD_MAP = ON | OFF [OFF] -- Force the use of std::map.
diff --git a/cpp/src/phonenumbers/phonenumbermatcher.cc b/cpp/src/phonenumbers/phonenumbermatcher.cc
index 9446226..164221d 100644
--- a/cpp/src/phonenumbers/phonenumbermatcher.cc
+++ b/cpp/src/phonenumbers/phonenumbermatcher.cc
@@ -160,13 +160,18 @@ bool AllNumberGroupsRemainGrouped(
}
bool LoadAlternateFormats(PhoneMetadataCollection* alternate_formats) {
+#if defined(I18N_PHONENUMBERS_USE_ALTERNATE_FORMATS)
if (!alternate_formats->ParseFromArray(alternate_format_get(),
alternate_format_size())) {
cerr << "Could not parse binary data." << endl;
return false;
}
return true;
+#else
+ return false;
+#endif
}
+
} // namespace
class PhoneNumberMatcherRegExps : public Singleton<PhoneNumberMatcherRegExps> {