OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <memory> |
| 10 |
9 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
10 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
11 #include "base/logging.h" | 13 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
16 #include "third_party/icu/source/common/unicode/ustring.h" | 17 #include "third_party/icu/source/common/unicode/ustring.h" |
17 #include "third_party/icu/source/i18n/unicode/numfmt.h" | 18 #include "third_party/icu/source/i18n/unicode/numfmt.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 // A simple wrapper around icu::NumberFormat that allows for resetting it | 24 // A simple wrapper around icu::NumberFormat that allows for resetting it |
24 // (as LazyInstance does not). | 25 // (as LazyInstance does not). |
25 struct NumberFormatWrapper { | 26 struct NumberFormatWrapper { |
26 NumberFormatWrapper() { | 27 NumberFormatWrapper() { |
27 Reset(); | 28 Reset(); |
28 } | 29 } |
29 | 30 |
30 void Reset() { | 31 void Reset() { |
31 // There's no ICU call to destroy a NumberFormat object other than | 32 // There's no ICU call to destroy a NumberFormat object other than |
32 // operator delete, so use the default Delete, which calls operator delete. | 33 // operator delete, so use the default Delete, which calls operator delete. |
33 // This can cause problems if a different allocator is used by this file | 34 // This can cause problems if a different allocator is used by this file |
34 // than by ICU. | 35 // than by ICU. |
35 UErrorCode status = U_ZERO_ERROR; | 36 UErrorCode status = U_ZERO_ERROR; |
36 number_format.reset(icu::NumberFormat::createInstance(status)); | 37 number_format.reset(icu::NumberFormat::createInstance(status)); |
37 DCHECK(U_SUCCESS(status)); | 38 DCHECK(U_SUCCESS(status)); |
38 } | 39 } |
39 | 40 |
40 scoped_ptr<icu::NumberFormat> number_format; | 41 std::unique_ptr<icu::NumberFormat> number_format; |
41 }; | 42 }; |
42 | 43 |
43 LazyInstance<NumberFormatWrapper> g_number_format_int = | 44 LazyInstance<NumberFormatWrapper> g_number_format_int = |
44 LAZY_INSTANCE_INITIALIZER; | 45 LAZY_INSTANCE_INITIALIZER; |
45 LazyInstance<NumberFormatWrapper> g_number_format_float = | 46 LazyInstance<NumberFormatWrapper> g_number_format_float = |
46 LAZY_INSTANCE_INITIALIZER; | 47 LAZY_INSTANCE_INITIALIZER; |
47 | 48 |
48 } // namespace | 49 } // namespace |
49 | 50 |
50 string16 FormatNumber(int64_t number) { | 51 string16 FormatNumber(int64_t number) { |
(...skipping 29 matching lines...) Expand all Loading... |
80 namespace testing { | 81 namespace testing { |
81 | 82 |
82 void ResetFormatters() { | 83 void ResetFormatters() { |
83 g_number_format_int.Get().Reset(); | 84 g_number_format_int.Get().Reset(); |
84 g_number_format_float.Get().Reset(); | 85 g_number_format_float.Get().Reset(); |
85 } | 86 } |
86 | 87 |
87 } // namespace testing | 88 } // namespace testing |
88 | 89 |
89 } // namespace base | 90 } // namespace base |
OLD | NEW |