Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: base/i18n/number_formatting.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/i18n/message_formatter_unittest.cc ('k') | base/i18n/time_formatting.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « base/i18n/message_formatter_unittest.cc ('k') | base/i18n/time_formatting.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698