From: philip.liard@gmail.com Date: Fri, 3 May 2013 13:49:35 +0000 (+0000) Subject: CPP: Make r570 compile in Chromium. X-Git-Tag: upstream/6.2.2~109 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4b697b915e27c9b8df3ac42d9cbb2751852f4ea1;p=platform%2Fupstream%2Flibphonenumber.git CPP: Make r570 compile in Chromium. This CL ensures that: - All declarations in headers are made in the i18n::phonenumbers namespace. - All USE flags/macros are prefixed with I18N_PHONENUMBERS_ to avoid name clashes. - All the code in base/ is actually used (by deleting unused code). - Outdated occurrences of USE_GOOGLE_BASE don't exist anymore. - Logging in PhoneNumberUtil is disabled by default (in production). However it can be enabled by calling PhoneNumberUtil::SetLogger() as it is now done during testing. BUG=http://crbug.com/236272 R=jia.shao.peng@gmail.com Review URL: https://codereview.appspot.com/9162043 git-svn-id: http://libphonenumber.googlecode.com/svn/trunk@571 ee073f10-1060-11df-b6a4-87a95322a99c --- diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 53e8b7e..d8c1382 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -127,7 +127,7 @@ if (${USE_STD_MAP} STREQUAL "OFF") INCLUDE (CheckIncludeFileCXX) CHECK_INCLUDE_FILE_CXX ("tr1/unordered_map" HAVE_CXX_TR1_UNORDERED_MAP) if (HAVE_CXX_TR1_UNORDERED_MAP) - add_definitions ("-DUSE_TR1_UNORDERED_MAP") + add_definitions ("-DI18N_PHONENUMBERS_USE_TR1_UNORDERED_MAP") endif () endif () @@ -215,12 +215,12 @@ if (${USE_RE2} STREQUAL "ON") # regexp_factory.h and regexp_adapter_test.cc. # When both ICU regexp and RE2 are defined, the regexp engine adapter defaults # to RE2 unless the ICU implementation is instantiated explictly obviously. - add_definitions (-DUSE_RE2) + add_definitions ("-DI18N_PHONENUMBERS_USE_RE2") list (APPEND SOURCES "src/phonenumbers/regexp_adapter_re2.cc") endif () if (${USE_ICU_REGEXP} STREQUAL "ON") - add_definitions (-DUSE_ICU_REGEXP) + 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") diff --git a/cpp/src/phonenumbers/base/basictypes.h b/cpp/src/phonenumbers/base/basictypes.h index 312252f..a35e9fc 100644 --- a/cpp/src/phonenumbers/base/basictypes.h +++ b/cpp/src/phonenumbers/base/basictypes.h @@ -4,7 +4,6 @@ #ifndef I18N_PHONENUMBERS_BASE_BASICTYPES_H_ #define I18N_PHONENUMBERS_BASE_BASICTYPES_H_ -#pragma once #include // So we can set the bounds of our types #include // For size_t @@ -15,6 +14,9 @@ #include // For intptr_t. #endif +namespace i18n { +namespace phonenumbers { + #ifdef INT64_MAX // INT64_MAX is defined if C99 stdint.h is included; use the @@ -94,26 +96,11 @@ typedef signed int char32; // A macro to disallow the copy constructor and operator= functions // This should be used in the private: declarations for a class +#if !defined(DISALLOW_COPY_AND_ASSIGN) #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ TypeName(const TypeName&); \ void operator=(const TypeName&) - -// An older, deprecated, politically incorrect name for the above. -// NOTE: The usage of this macro was baned from our code base, but some -// third_party libraries are yet using it. -// TODO(tfarina): Figure out how to fix the usage of this macro in the -// third_party libraries and get rid of it. -#define DISALLOW_EVIL_CONSTRUCTORS(TypeName) DISALLOW_COPY_AND_ASSIGN(TypeName) - -// A macro to disallow all the implicit constructors, namely the -// default constructor, copy constructor and operator= functions. -// -// This should be used in the private: declarations for a class -// that wants to prevent anyone from instantiating it. This is -// especially useful for classes containing only static methods. -#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ - TypeName(); \ - DISALLOW_COPY_AND_ASSIGN(TypeName) +#endif // The arraysize(arr) macro returns the # of elements in an array arr. // The expression is a compile-time constant, and therefore can be @@ -140,7 +127,9 @@ template char (&ArraySizeHelper(const T (&array)[N]))[N]; #endif +#if !defined(arraysize) #define arraysize(array) (sizeof(ArraySizeHelper(array))) +#endif // ARRAYSIZE_UNSAFE performs essentially the same calculation as arraysize, // but can be used on anonymous types or types defined inside @@ -179,32 +168,11 @@ char (&ArraySizeHelper(const T (&array)[N]))[N]; // where a pointer is 4 bytes, this means all pointers to a type whose // size is 3 or greater than 4 will be (righteously) rejected. +#if !defined(ARRAYSIZE_UNSAFE) #define ARRAYSIZE_UNSAFE(a) \ ((sizeof(a) / sizeof(*(a))) / \ static_cast(!(sizeof(a) % sizeof(*(a))))) - - -// Use implicit_cast as a safe version of static_cast or const_cast -// for upcasting in the type hierarchy (i.e. casting a pointer to Foo -// to a pointer to SuperclassOfFoo or casting a pointer to Foo to -// a const pointer to Foo). -// When you use implicit_cast, the compiler checks that the cast is safe. -// Such explicit implicit_casts are necessary in surprisingly many -// situations where C++ demands an exact type match instead of an -// argument type convertable to a target type. -// -// The From type can be inferred, so the preferred syntax for using -// implicit_cast is the same as for static_cast etc.: -// -// implicit_cast(expr) -// -// implicit_cast would have been part of the C++ standard library, -// but the proposal was submitted too late. It will probably make -// its way into the language in the future. -template -inline To implicit_cast(From const &f) { - return f; -} +#endif // The COMPILE_ASSERT macro can be used to verify that a compile time // expression is true. For example, you could use it to verify the @@ -225,61 +193,12 @@ template struct CompileAssert { }; -#undef COMPILE_ASSERT +#if !defined(COMPILE_ASSERT) #define COMPILE_ASSERT(expr, msg) \ typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] +#endif -// Implementation details of COMPILE_ASSERT: -// -// - COMPILE_ASSERT works by defining an array type that has -1 -// elements (and thus is invalid) when the expression is false. -// -// - The simpler definition -// -// #define COMPILE_ASSERT(expr, msg) typedef char msg[(expr) ? 1 : -1] -// -// does not work, as gcc supports variable-length arrays whose sizes -// are determined at run-time (this is gcc's extension and not part -// of the C++ standard). As a result, gcc fails to reject the -// following code with the simple definition: -// -// int foo; -// COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is -// // not a compile-time constant. -// -// - By using the type CompileAssert<(bool(expr))>, we ensures that -// expr is a compile-time constant. (Template arguments must be -// determined at compile-time.) -// -// - The outter parentheses in CompileAssert<(bool(expr))> are necessary -// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written -// -// CompileAssert -// -// instead, these compilers will refuse to compile -// -// COMPILE_ASSERT(5 > 0, some_message); -// -// (They seem to think the ">" in "5 > 0" marks the end of the -// template argument list.) -// -// - The array size is (bool(expr) ? 1 : -1), instead of simply -// -// ((expr) ? 1 : -1). -// -// This is to avoid running into a bug in MS VC 7.1, which -// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1. - -// Used to explicitly mark the return value of a function as unused. If you are -// really sure you don't want to do anything with the return value of a function -// that has been marked WARN_UNUSED_RESULT, wrap it with this. Example: -// -// scoped_ptr my_var = ...; -// if (TakeOwnership(my_var.get()) == SUCCESS) -// ignore_result(my_var.release()); -// -template -inline void ignore_result(const T&) { -} +} // namespace phonenumbers +} // namespace i18n #endif // I18N_PHONENUMBERS_BASE_BASICTYPES_H_ diff --git a/cpp/src/phonenumbers/base/memory/scoped_ptr.h b/cpp/src/phonenumbers/base/memory/scoped_ptr.h index 5619e11..5c3e931 100644 --- a/cpp/src/phonenumbers/base/memory/scoped_ptr.h +++ b/cpp/src/phonenumbers/base/memory/scoped_ptr.h @@ -93,8 +93,6 @@ struct FreeDeleter { } }; -namespace internal { - // Minimal implementation of the core logic of scoped_ptr, suitable for // reuse in both scoped_ptr and its specializations. template @@ -197,10 +195,6 @@ class scoped_ptr_impl { DISALLOW_COPY_AND_ASSIGN(scoped_ptr_impl); }; -} // namespace internal -} // namespace phonenumbers -} // namespace i18n - // A scoped_ptr is like a T*, except that the destructor of scoped_ptr // automatically deletes the pointer it holds (if any). // That is, scoped_ptr owns the T object that it points to. @@ -217,7 +211,7 @@ class scoped_ptr_impl { // unique_ptr<> features. Known deficiencies include not supporting move-only // deleteres, function pointers as deleters, and deleters with reference // types. -template > +template > class scoped_ptr { public: // The element and deleter types. @@ -245,8 +239,7 @@ class scoped_ptr { // implementation of scoped_ptr. template scoped_ptr(scoped_ptr other) : impl_(&other.impl_) { - COMPILE_ASSERT(!i18n::phonenumbers::is_array::value, - U_cannot_be_an_array); + COMPILE_ASSERT(!is_array::value, U_cannot_be_an_array); } // operator=. Allows assignment from a scoped_ptr rvalue for a convertible @@ -261,8 +254,7 @@ class scoped_ptr { // scoped_ptr. template scoped_ptr& operator=(scoped_ptr rhs) { - COMPILE_ASSERT(!i18n::phonenumbers::is_array::value, - U_cannot_be_an_array); + COMPILE_ASSERT(!is_array::value, U_cannot_be_an_array); impl_.TakeState(&rhs.impl_); return *this; } @@ -290,8 +282,7 @@ class scoped_ptr { // Allow scoped_ptr to be used in boolean expressions, but not // implicitly convertible to a real bool (which is dangerous). private: - typedef i18n::phonenumbers::internal::scoped_ptr_impl< - element_type, deleter_type> scoped_ptr::*Testable; + typedef scoped_ptr_impl scoped_ptr::*Testable; public: operator Testable() const { return impl_.get() ? &scoped_ptr::impl_ : NULL; } @@ -319,8 +310,7 @@ class scoped_ptr { private: // Needed to reach into |impl_| in the constructor. template friend class scoped_ptr; - i18n::phonenumbers::internal::scoped_ptr_impl< - element_type, deleter_type> impl_; + scoped_ptr_impl impl_; // Forbid comparison of scoped_ptr types. If U != T, it totally // doesn't make sense, and if U == T, it still doesn't make sense @@ -376,8 +366,7 @@ class scoped_ptr { // Allow scoped_ptr to be used in boolean expressions, but not // implicitly convertible to a real bool (which is dangerous). private: - typedef i18n::phonenumbers::internal::scoped_ptr_impl< - element_type, deleter_type> scoped_ptr::*Testable; + typedef scoped_ptr_impl scoped_ptr::*Testable; public: operator Testable() const { return impl_.get() ? &scoped_ptr::impl_ : NULL; } @@ -407,8 +396,7 @@ class scoped_ptr { enum { type_must_be_complete = sizeof(element_type) }; // Actually hold the data. - i18n::phonenumbers::internal::scoped_ptr_impl< - element_type, deleter_type> impl_; + scoped_ptr_impl impl_; // Disable initialization from any type other than element_type*, by // providing a constructor that matches such an initialization, but is @@ -455,5 +443,8 @@ scoped_ptr make_scoped_ptr(T* ptr) { return scoped_ptr(ptr); } +} // namespace phonenumbers +} // namespace i18n + #endif // !I18N_PHONENUMBERS_USE_BOOST #endif // I18N_PHONENUMBERS_BASE_MEMORY_SCOPED_PTR_H_ diff --git a/cpp/src/phonenumbers/base/thread_checker.h b/cpp/src/phonenumbers/base/thread_checker.h index 38ef54c..bac8048 100644 --- a/cpp/src/phonenumbers/base/thread_checker.h +++ b/cpp/src/phonenumbers/base/thread_checker.h @@ -14,8 +14,8 @@ // Author: Philippe Liard -#ifndef I18N_PHONENUMBERS_BASE_THREAD_SAFETY_CHECK_H_ -#define I18N_PHONENUMBERS_BASE_THREAD_SAFETY_CHECK_H_ +#ifndef I18N_PHONENUMBERS_BASE_THREAD_CHECKER_H_ +#define I18N_PHONENUMBERS_BASE_THREAD_CHECKER_H_ #if !defined(I18N_PHONENUMBERS_USE_BOOST) @@ -23,7 +23,8 @@ // user of the library know that it can't be used in a thread-safe manner when // it is not depending on Boost. #if !defined(I18N_PHONENUMBERS_NO_THREAD_SAFETY) -#error "Building without Boost, please provide -DNO_THREAD_SAFETY" +#error Building without Boost, please provide \ + -DI18N_PHONENUMBERS_NO_THREAD_SAFETY #endif #endif @@ -65,4 +66,4 @@ class ThreadChecker { } // namespace phonenumbers } // namespace i18n -#endif // I18N_PHONENUMBERS_BASE_THREAD_SAFETY_CHECK_H_ +#endif // I18N_PHONENUMBERS_BASE_THREAD_CHECKER_H_ diff --git a/cpp/src/phonenumbers/default_logger.cc b/cpp/src/phonenumbers/default_logger.cc index 49d5513..44379a5 100644 --- a/cpp/src/phonenumbers/default_logger.cc +++ b/cpp/src/phonenumbers/default_logger.cc @@ -14,9 +14,6 @@ // Author: Philippe Liard -// This file should not be compiled when using Google base/. -#ifndef USE_GOOGLE_BASE - #include #include "phonenumbers/default_logger.h" @@ -50,5 +47,3 @@ void StdoutLogger::WriteLevel() { } // namespace phonenumbers } // namespace i18n - -#endif // USE_GOOGLE_BASE diff --git a/cpp/src/phonenumbers/default_logger.h b/cpp/src/phonenumbers/default_logger.h index d6ba050..afb6fc9 100644 --- a/cpp/src/phonenumbers/default_logger.h +++ b/cpp/src/phonenumbers/default_logger.h @@ -19,33 +19,16 @@ #include "phonenumbers/logger.h" -#ifdef USE_GOOGLE_BASE +#include +#include namespace i18n { namespace phonenumbers { -// If Google base/ is used, LOG() and VLOG() from base/logging.h are used -// therefore the default logger implementation (StdoutLogger) instantiated in -// phonenumberutil will actually never be used. -typedef NullLogger StdoutLogger; - -} // namespace phonenumbers -} // namespace i18n - -#else - -#include -#include - +using i18n::phonenumbers::Logger; using std::string; using std::stringstream; -// Make the logging functions private (not declared in logger.h) as the client -// should not have any reason to use them. -namespace { - -using i18n::phonenumbers::Logger; - // Class template used to inline the right implementation for the T -> string // conversion. template @@ -91,11 +74,6 @@ class LoggerHandler { Logger* const impl_; }; -} // namespace - -namespace i18n { -namespace phonenumbers { - inline LoggerHandler VLOG(int n) { Logger* const logger_impl = Logger::mutable_logger_impl(); if (logger_impl->level() < n) { @@ -122,5 +100,4 @@ class StdoutLogger : public Logger { } // namespace phonenumbers } // namespace i18n -#endif // USE_GOOGLE_BASE #endif // I18N_PHONENUMBERS_DEFAULT_LOGGER_H_ diff --git a/cpp/src/phonenumbers/phonenumbermatcher.cc b/cpp/src/phonenumbers/phonenumbermatcher.cc index 039ff90..9446226 100644 --- a/cpp/src/phonenumbers/phonenumbermatcher.cc +++ b/cpp/src/phonenumbers/phonenumbermatcher.cc @@ -20,9 +20,10 @@ #include "phonenumbers/phonenumbermatcher.h" -#ifndef USE_ICU_REGEXP -#error phonenumbermatcher depends on ICU (i.e. USE_ICU_REGEXP must be set) -#endif // USE_ICU_REGEXP +#ifndef I18N_PHONENUMBERS_USE_ICU_REGEXP +#error phonenumbermatcher depends on ICU \ + (i.e. I18N_PHONENUMBERS_USE_ICU_REGEXP must be set) +#endif // I18N_PHONENUMBERS_USE_ICU_REGEXP #include #include @@ -51,9 +52,9 @@ #include "phonenumbers/regexp_adapter_icu.h" #include "phonenumbers/stringutil.h" -#ifdef USE_RE2 +#ifdef I18N_PHONENUMBERS_USE_RE2 #include "phonenumbers/regexp_adapter_re2.h" -#endif // USE_RE2_AND_ICU +#endif // I18N_PHONENUMBERS_USE_RE2_AND_ICU using std::cerr; using std::endl; @@ -168,14 +169,10 @@ bool LoadAlternateFormats(PhoneMetadataCollection* alternate_formats) { } } // namespace -#ifdef USE_GOOGLE_BASE -class PhoneNumberMatcherRegExps { - friend struct DefaultSingletonTraits; -#else class PhoneNumberMatcherRegExps : public Singleton { - friend class Singleton; -#endif // USE_GOOGLE_BASE private: + friend class Singleton; + string opening_parens_; string closing_parens_; string non_parens_; @@ -248,12 +245,6 @@ class PhoneNumberMatcherRegExps : public Singleton { // Phone number pattern allowing optional punctuation. scoped_ptr pattern_; -#ifdef USE_GOOGLE_BASE - static PhoneNumberMatcherRegExps* GetInstance() { - return Singleton::get(); - } -#endif // USE_GOOGLE_BASE - PhoneNumberMatcherRegExps() : opening_parens_("(\\[\xEF\xBC\x88\xEF\xBC\xBB" /* "(\\[([" */), closing_parens_(")\\]\xEF\xBC\x89\xEF\xBC\xBD" /* ")\\])]" */), @@ -281,11 +272,11 @@ class PhoneNumberMatcherRegExps : public Singleton { PhoneNumberUtil::GetInstance()->GetExtnPatternsForMatching(), ")?")), regexp_factory_for_pattern_(new ICURegExpFactory()), -#ifdef USE_RE2 +#ifdef I18N_PHONENUMBERS_USE_RE2 regexp_factory_(new RE2RegExpFactory()), #else regexp_factory_(new ICURegExpFactory()), -#endif // USE_RE2 +#endif // I18N_PHONENUMBERS_USE_RE2 pub_pages_(regexp_factory_->CreateRegExp( "\\d{1,5}-+\\d{1,5}\\s{0,4}\\(\\d{1,4}")), slash_separated_dates_(regexp_factory_->CreateRegExp( @@ -315,24 +306,12 @@ class PhoneNumberMatcherRegExps : public Singleton { DISALLOW_COPY_AND_ASSIGN(PhoneNumberMatcherRegExps); }; -#ifdef USE_GOOGLE_BASE -class AlternateFormats { - friend struct DefaultSingletonTraits; -#else class AlternateFormats : public Singleton { - friend class Singleton; -#endif // USE_GOOGLE_BASE public: PhoneMetadataCollection format_data_; map calling_code_to_alternate_formats_map_; -#ifdef USE_GOOGLE_BASE - static AlternateFormats* GetInstance() { - return Singleton::get(); - } -#endif // USE_GOOGLE_BASE - AlternateFormats() : format_data_(), calling_code_to_alternate_formats_map_() { diff --git a/cpp/src/phonenumbers/phonenumberutil.cc b/cpp/src/phonenumbers/phonenumberutil.cc index a7967a7..317e14a 100644 --- a/cpp/src/phonenumbers/phonenumberutil.cc +++ b/cpp/src/phonenumbers/phonenumberutil.cc @@ -369,7 +369,8 @@ PhoneNumberUtil::ValidationResult TestNumberLengthAgainstPattern( } // namespace void PhoneNumberUtil::SetLogger(Logger* logger) { - Logger::set_logger_impl(logger); + logger_.reset(logger); + Logger::set_logger_impl(logger_.get()); } class PhoneNumberRegExpsAndMappings { @@ -657,7 +658,7 @@ class PhoneNumberRegExpsAndMappings { // Private constructor. Also takes care of initialisation. PhoneNumberUtil::PhoneNumberUtil() - : logger_(Logger::set_logger_impl(new StdoutLogger())), + : logger_(Logger::set_logger_impl(new NullLogger())), reg_exps_(new PhoneNumberRegExpsAndMappings), country_calling_code_to_region_code_map_(new vector()), nanpa_regions_(new set()), @@ -739,11 +740,9 @@ void PhoneNumberUtil::GetSupportedRegions(set* regions) const { // Public wrapper function to get a PhoneNumberUtil instance with the default // metadata file. // static -#ifdef USE_GOOGLE_BASE PhoneNumberUtil* PhoneNumberUtil::GetInstance() { - return Singleton::get(); + return Singleton::GetInstance(); } -#endif const string& PhoneNumberUtil::GetExtnPatternsForMatching() const { return reg_exps_->extn_patterns_for_matching_; diff --git a/cpp/src/phonenumbers/phonenumberutil.h b/cpp/src/phonenumbers/phonenumberutil.h index 1ba4ddf..528e584 100644 --- a/cpp/src/phonenumbers/phonenumberutil.h +++ b/cpp/src/phonenumbers/phonenumberutil.h @@ -59,13 +59,8 @@ class RegExp; // codes can be found here: // http://www.iso.org/iso/english_country_names_and_code_elements -#ifdef USE_GOOGLE_BASE -class PhoneNumberUtil { - friend struct DefaultSingletonTraits; -#else class PhoneNumberUtil : public Singleton { - friend class Singleton; -#endif + private: friend class AsYouTypeFormatter; friend class PhoneNumberMatcher; friend class PhoneNumberMatcherRegExps; @@ -74,6 +69,8 @@ class PhoneNumberUtil : public Singleton { friend class PhoneNumberUtilTest; friend class ShortNumberUtil; friend class ShortNumberUtilTest; + friend class Singleton; + public: ~PhoneNumberUtil(); static const char kRegionCodeForNonGeoEntity[]; @@ -172,9 +169,7 @@ class PhoneNumberUtil : public Singleton { // // The PhoneNumberUtil is implemented as a singleton. Therefore, calling // GetInstance multiple times will only result in one instance being created. -#ifdef USE_GOOGLE_BASE static PhoneNumberUtil* GetInstance(); -#endif // Returns true if the number is a valid vanity (alpha) number such as 800 // MICROSOFT. A valid vanity number will start with at least 3 digits and will @@ -552,9 +547,9 @@ class PhoneNumberUtil : public Singleton { MatchType IsNumberMatchWithOneString(const PhoneNumber& first_number, const string& second_number) const; - // Overrides the default logging system. The provided logger destruction is - // handled by this class (i.e don't delete it). - static void SetLogger(Logger* logger); + // Overrides the default logging system. This takes ownership of the provided + // logger. + void SetLogger(Logger* logger); // Gets an AsYouTypeFormatter for the specific region. // Returns an AsYouTypeFormatter object, which could be used to format phone diff --git a/cpp/src/phonenumbers/regexp_cache.cc b/cpp/src/phonenumbers/regexp_cache.cc index dbd7676..d010aee 100644 --- a/cpp/src/phonenumbers/regexp_cache.cc +++ b/cpp/src/phonenumbers/regexp_cache.cc @@ -31,7 +31,7 @@ namespace phonenumbers { RegExpCache::RegExpCache(const AbstractRegExpFactory& regexp_factory, size_t min_items) : regexp_factory_(regexp_factory), -#ifdef USE_TR1_UNORDERED_MAP +#ifdef I18N_PHONENUMBERS_USE_TR1_UNORDERED_MAP cache_impl_(new CacheImpl(min_items)) #else cache_impl_(new CacheImpl()) diff --git a/cpp/src/phonenumbers/regexp_cache.h b/cpp/src/phonenumbers/regexp_cache.h index c2c471a..75fcace 100644 --- a/cpp/src/phonenumbers/regexp_cache.h +++ b/cpp/src/phonenumbers/regexp_cache.h @@ -34,7 +34,7 @@ #include "phonenumbers/base/memory/scoped_ptr.h" #include "phonenumbers/base/synchronization/lock.h" -#ifdef USE_TR1_UNORDERED_MAP +#ifdef I18N_PHONENUMBERS_USE_TR1_UNORDERED_MAP # include #else # include @@ -50,7 +50,7 @@ class RegExp; class RegExpCache { private: -#ifdef USE_TR1_UNORDERED_MAP +#ifdef I18N_PHONENUMBERS_USE_TR1_UNORDERED_MAP typedef std::tr1::unordered_map CacheImpl; #else typedef std::map CacheImpl; diff --git a/cpp/src/phonenumbers/regexp_factory.h b/cpp/src/phonenumbers/regexp_factory.h index 318896a..3e69b43 100644 --- a/cpp/src/phonenumbers/regexp_factory.h +++ b/cpp/src/phonenumbers/regexp_factory.h @@ -18,25 +18,25 @@ #define I18N_PHONENUMBERS_REGEXP_ADAPTER_FACTORY_H_ // This file selects the right implementation of the abstract regexp factory at -// compile time depending on the compilation flags (USE_RE2). The default -// abstract regexp factory implementation can be obtained using the type -// RegExpFactory. This will be set to RE2RegExpFactory if RE2 is used or +// compile time depending on the compilation flags (I18N_PHONENUMBERS_USE_RE2). +// The default abstract regexp factory implementation can be obtained using the +// type RegExpFactory. This will be set to RE2RegExpFactory if RE2 is used or // ICURegExpFactory otherwise. -#ifdef USE_RE2 +#ifdef I18N_PHONENUMBERS_USE_RE2 #include "phonenumbers/regexp_adapter_re2.h" #else #include "phonenumbers/regexp_adapter_icu.h" -#endif // USE_RE2 +#endif // I18N_PHONENUMBERS_USE_RE2 namespace i18n { namespace phonenumbers { -#ifdef USE_RE2 +#ifdef I18N_PHONENUMBERS_USE_RE2 typedef RE2RegExpFactory RegExpFactory; #else typedef ICURegExpFactory RegExpFactory; -#endif // USE_RE2 +#endif // I18N_PHONENUMBERS_USE_RE2 } // namespace phonenumbers } // namespace i18n diff --git a/cpp/src/phonenumbers/utf/unicodetext.cc b/cpp/src/phonenumbers/utf/unicodetext.cc index 262a129..175d1f9 100644 --- a/cpp/src/phonenumbers/utf/unicodetext.cc +++ b/cpp/src/phonenumbers/utf/unicodetext.cc @@ -19,12 +19,14 @@ #include #include "phonenumbers/utf/unicodetext.h" -//#include "phonenumbers/base/logging.h" #include "phonenumbers/utf/stringpiece.h" //#include "utf/stringprintf.h" #include "phonenumbers/utf/utf.h" #include "phonenumbers/utf/unilib.h" +namespace i18n { +namespace phonenumbers { + using std::stringstream; using std::max; using std::hex; @@ -512,3 +514,6 @@ string UnicodeText::const_iterator::DebugString() const { return result; } + +} // namespace phonenumbers +} // namespace i18n diff --git a/cpp/src/phonenumbers/utf/unicodetext.h b/cpp/src/phonenumbers/utf/unicodetext.h index 990842d..5c1d584 100644 --- a/cpp/src/phonenumbers/utf/unicodetext.h +++ b/cpp/src/phonenumbers/utf/unicodetext.h @@ -21,7 +21,9 @@ #include #include #include "phonenumbers/base/basictypes.h" -//#include "util/utf8/public/config.h" + +namespace i18n { +namespace phonenumbers { using std::string; using std::bidirectional_iterator_tag; @@ -453,4 +455,7 @@ inline string UnicodeTextToUTF8(const UnicodeText& t) { return string(t.utf8_data(), t.utf8_length()); } +} // namespace phonenumbers +} // namespace i18n + #endif // UTIL_UTF8_UNICODETEXT_H__ diff --git a/cpp/src/phonenumbers/utf/unilib.cc b/cpp/src/phonenumbers/utf/unilib.cc index 064c724..ffcb8b0 100644 --- a/cpp/src/phonenumbers/utf/unilib.cc +++ b/cpp/src/phonenumbers/utf/unilib.cc @@ -21,6 +21,8 @@ #include "phonenumbers/base/basictypes.h" #include "phonenumbers/utf/utf.h" +namespace i18n { +namespace phonenumbers { namespace UniLib { namespace { @@ -62,3 +64,5 @@ int SpanInterchangeValid(const char* begin, int byte_length) { } } // namespace UniLib +} // namespace phonenumbers +} // namespace i18n diff --git a/cpp/src/phonenumbers/utf/unilib.h b/cpp/src/phonenumbers/utf/unilib.h index b70966c..1230002 100644 --- a/cpp/src/phonenumbers/utf/unilib.h +++ b/cpp/src/phonenumbers/utf/unilib.h @@ -34,6 +34,8 @@ #include #include "phonenumbers/base/basictypes.h" +namespace i18n { +namespace phonenumbers { namespace UniLib { // Returns true unless a surrogate code point @@ -91,5 +93,7 @@ inline bool IsInterchangeValid(const std::string& src) { } } // namespace UniLib +} // namespace phonenumbers +} // namespace i18n #endif // UTIL_UTF8_PUBLIC_UNILIB_H_ diff --git a/cpp/test/phonenumbers/asyoutypeformatter_test.cc b/cpp/test/phonenumbers/asyoutypeformatter_test.cc index 7581f45..8a36e27 100644 --- a/cpp/test/phonenumbers/asyoutypeformatter_test.cc +++ b/cpp/test/phonenumbers/asyoutypeformatter_test.cc @@ -24,6 +24,7 @@ #include "phonenumbers/base/logging.h" #include "phonenumbers/base/memory/scoped_ptr.h" +#include "phonenumbers/default_logger.h" #include "phonenumbers/phonenumberutil.h" #include "phonenumbers/test_util.h" @@ -35,6 +36,7 @@ class PhoneMetadata; class AsYouTypeFormatterTest : public testing::Test { protected: AsYouTypeFormatterTest() : phone_util_(*PhoneNumberUtil::GetInstance()) { + PhoneNumberUtil::GetInstance()->SetLogger(new StdoutLogger()); } const PhoneMetadata* GetCurrentMetadata() const { diff --git a/cpp/test/phonenumbers/phonenumbermatcher_test.cc b/cpp/test/phonenumbers/phonenumbermatcher_test.cc index 5a948e4..f19c637 100644 --- a/cpp/test/phonenumbers/phonenumbermatcher_test.cc +++ b/cpp/test/phonenumbers/phonenumbermatcher_test.cc @@ -25,6 +25,7 @@ #include "phonenumbers/base/basictypes.h" #include "phonenumbers/base/memory/scoped_ptr.h" #include "phonenumbers/base/memory/singleton.h" +#include "phonenumbers/default_logger.h" #include "phonenumbers/phonenumber.h" #include "phonenumbers/phonenumber.pb.h" #include "phonenumbers/phonenumbermatch.h" @@ -77,6 +78,7 @@ class PhoneNumberMatcherTest : public testing::Test { RegionCode::US(), PhoneNumberMatcher::VALID, 5), offset_(0) { + PhoneNumberUtil::GetInstance()->SetLogger(new StdoutLogger()); } bool IsLatinLetter(char32 letter) { diff --git a/cpp/test/phonenumbers/phonenumberutil_test.cc b/cpp/test/phonenumbers/phonenumberutil_test.cc index c8115a3..f170a7b 100644 --- a/cpp/test/phonenumbers/phonenumberutil_test.cc +++ b/cpp/test/phonenumbers/phonenumberutil_test.cc @@ -30,6 +30,7 @@ #include +#include "phonenumbers/default_logger.h" #include "phonenumbers/phonemetadata.pb.h" #include "phonenumbers/phonenumber.h" #include "phonenumbers/phonenumber.pb.h" @@ -50,6 +51,7 @@ static const int kInvalidCountryCode = 2; class PhoneNumberUtilTest : public testing::Test { protected: PhoneNumberUtilTest() : phone_util_(*PhoneNumberUtil::GetInstance()) { + PhoneNumberUtil::GetInstance()->SetLogger(new StdoutLogger()); } // Wrapper functions for private functions that we want to test. diff --git a/cpp/test/phonenumbers/shortnumberutil_test.cc b/cpp/test/phonenumbers/shortnumberutil_test.cc index 663517b..090fdbe 100644 --- a/cpp/test/phonenumbers/shortnumberutil_test.cc +++ b/cpp/test/phonenumbers/shortnumberutil_test.cc @@ -16,6 +16,7 @@ #include +#include "phonenumbers/default_logger.h" #include "phonenumbers/phonenumberutil.h" #include "phonenumbers/shortnumberutil.h" #include "phonenumbers/test_util.h" @@ -26,6 +27,7 @@ namespace phonenumbers { class ShortNumberUtilTest : public testing::Test { protected: ShortNumberUtilTest() : short_util_() { + PhoneNumberUtil::GetInstance()->SetLogger(new StdoutLogger()); } const ShortNumberUtil short_util_; diff --git a/cpp/test/phonenumbers/utf/unicodetext_test.cc b/cpp/test/phonenumbers/utf/unicodetext_test.cc index 0e52230..5e51476 100644 --- a/cpp/test/phonenumbers/utf/unicodetext_test.cc +++ b/cpp/test/phonenumbers/utf/unicodetext_test.cc @@ -19,7 +19,7 @@ #include "phonenumbers/utf/unicodetext.h" namespace i18n { -namespace unicodetext { +namespace phonenumbers { TEST(UnicodeTextTest, Iterator) { struct value { @@ -41,5 +41,5 @@ TEST(UnicodeTextTest, Iterator) { } } -} // namespace unicodetext +} // namespace phonenumbers } // namespace i18n