| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/i18n/number_formatting.h" | 5 #include "base/i18n/number_formatting.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // This can cause problems if a different allocator is used by this file | 29 // This can cause problems if a different allocator is used by this file |
| 30 // than by ICU. | 30 // than by ICU. |
| 31 UErrorCode status = U_ZERO_ERROR; | 31 UErrorCode status = U_ZERO_ERROR; |
| 32 number_format.reset(icu::NumberFormat::createInstance(status)); | 32 number_format.reset(icu::NumberFormat::createInstance(status)); |
| 33 DCHECK(U_SUCCESS(status)); | 33 DCHECK(U_SUCCESS(status)); |
| 34 } | 34 } |
| 35 | 35 |
| 36 scoped_ptr<icu::NumberFormat> number_format; | 36 scoped_ptr<icu::NumberFormat> number_format; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 LazyInstance<NumberFormatWrapper> g_number_format_int(LINKER_INITIALIZED); | 39 LazyInstance<NumberFormatWrapper> g_number_format_int = |
| 40 LazyInstance<NumberFormatWrapper> g_number_format_float(LINKER_INITIALIZED); | 40 LAZY_INSTANCE_INITIALIZER; |
| 41 LazyInstance<NumberFormatWrapper> g_number_format_float = |
| 42 LAZY_INSTANCE_INITIALIZER; |
| 41 | 43 |
| 42 } // namespace | 44 } // namespace |
| 43 | 45 |
| 44 string16 FormatNumber(int64 number) { | 46 string16 FormatNumber(int64 number) { |
| 45 icu::NumberFormat* number_format = | 47 icu::NumberFormat* number_format = |
| 46 g_number_format_int.Get().number_format.get(); | 48 g_number_format_int.Get().number_format.get(); |
| 47 | 49 |
| 48 if (!number_format) { | 50 if (!number_format) { |
| 49 // As a fallback, just return the raw number in a string. | 51 // As a fallback, just return the raw number in a string. |
| 50 return UTF8ToUTF16(StringPrintf("%" PRId64, number)); | 52 return UTF8ToUTF16(StringPrintf("%" PRId64, number)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 74 namespace testing { | 76 namespace testing { |
| 75 | 77 |
| 76 void ResetFormatters() { | 78 void ResetFormatters() { |
| 77 g_number_format_int.Get().Reset(); | 79 g_number_format_int.Get().Reset(); |
| 78 g_number_format_float.Get().Reset(); | 80 g_number_format_float.Get().Reset(); |
| 79 } | 81 } |
| 80 | 82 |
| 81 } // namespace testing | 83 } // namespace testing |
| 82 | 84 |
| 83 } // namespace base | 85 } // namespace base |
| OLD | NEW |