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

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

Issue 2042003: Switch some Singletons to use LeakySingleton. Base URL: http://src.chromium.org/git/chromium.git
Patch Set: More build fixes. Created 10 years, 7 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/file_util_icu.cc ('k') | base/linux_util.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) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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/singleton.h" 9 #include "base/singleton.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "unicode/numfmt.h" 12 #include "unicode/numfmt.h"
13 #include "unicode/ustring.h" 13 #include "unicode/ustring.h"
14 14
15 namespace base { 15 namespace base {
16 16
17 namespace { 17 namespace {
18 18
19 struct NumberFormatSingletonTraits 19 struct NumberFormatSingletonTraits
20 : public DefaultSingletonTraits<icu::NumberFormat> { 20 : public DefaultSingletonTraits<icu::NumberFormat> {
21 static icu::NumberFormat* New() { 21 static icu::NumberFormat* New() {
22 UErrorCode status = U_ZERO_ERROR; 22 UErrorCode status = U_ZERO_ERROR;
23 icu::NumberFormat* formatter = icu::NumberFormat::createInstance(status); 23 icu::NumberFormat* formatter = icu::NumberFormat::createInstance(status);
24 DCHECK(U_SUCCESS(status)); 24 DCHECK(U_SUCCESS(status));
25 return formatter; 25 return formatter;
26 } 26 }
27 // There's no ICU call to destroy a NumberFormat object other than 27
28 // operator delete, so use the default Delete, which calls operator delete. 28 // Don't bother to delete.
29 // This can cause problems if a different allocator is used by this file than 29 static const bool kRegisterAtExit = false;
30 // by ICU.
31 }; 30 };
32 31
33 } // namespace 32 } // namespace
34 33
35 string16 FormatNumber(int64 number) { 34 string16 FormatNumber(int64 number) {
36 icu::NumberFormat* number_format = 35 icu::NumberFormat* number_format =
37 Singleton<icu::NumberFormat, NumberFormatSingletonTraits>::get(); 36 Singleton<icu::NumberFormat, NumberFormatSingletonTraits>::get();
38 37
39 if (!number_format) { 38 if (!number_format) {
40 // As a fallback, just return the raw number in a string. 39 // As a fallback, just return the raw number in a string.
41 return UTF8ToUTF16(StringPrintf("%" PRId64, number)); 40 return UTF8ToUTF16(StringPrintf("%" PRId64, number));
42 } 41 }
43 icu::UnicodeString ustr; 42 icu::UnicodeString ustr;
44 number_format->format(number, ustr); 43 number_format->format(number, ustr);
45 44
46 return string16(ustr.getBuffer(), static_cast<size_t>(ustr.length())); 45 return string16(ustr.getBuffer(), static_cast<size_t>(ustr.length()));
47 } 46 }
48 47
49 } // namespace base 48 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/file_util_icu.cc ('k') | base/linux_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698