diff options
Diffstat (limited to 'base/i18n')
-rw-r--r-- | base/i18n/number_formatting.cc | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/base/i18n/number_formatting.cc b/base/i18n/number_formatting.cc index 7a69294..df6af14 100644 --- a/base/i18n/number_formatting.cc +++ b/base/i18n/number_formatting.cc @@ -6,7 +6,8 @@ #include "base/format_macros.h" #include "base/logging.h" -#include "base/singleton.h" +#include "base/lazy_instance.h" +#include "base/scoped_ptr.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "unicode/numfmt.h" @@ -16,25 +17,26 @@ namespace base { namespace { -struct NumberFormatSingletonTraits - : public DefaultSingletonTraits<icu::NumberFormat> { - static icu::NumberFormat* New() { +struct NumberFormatWrapper { + NumberFormatWrapper() { + // There's no ICU call to destroy a NumberFormat object other than + // operator delete, so use the default Delete, which calls operator delete. + // This can cause problems if a different allocator is used by this file + // than by ICU. UErrorCode status = U_ZERO_ERROR; - icu::NumberFormat* formatter = icu::NumberFormat::createInstance(status); + number_format.reset(icu::NumberFormat::createInstance(status)); DCHECK(U_SUCCESS(status)); - return formatter; } - // There's no ICU call to destroy a NumberFormat object other than - // operator delete, so use the default Delete, which calls operator delete. - // This can cause problems if a different allocator is used by this file than - // by ICU. + + scoped_ptr<icu::NumberFormat> number_format; }; } // namespace +static LazyInstance<NumberFormatWrapper> g_number_format(LINKER_INITIALIZED); + string16 FormatNumber(int64 number) { - icu::NumberFormat* number_format = - Singleton<icu::NumberFormat, NumberFormatSingletonTraits>::get(); + icu::NumberFormat* number_format = g_number_format.Get().number_format.get(); if (!number_format) { // As a fallback, just return the raw number in a string. |