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

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

Issue 2740673002: Prepare Chromium and Blink for ICU 59 (Closed)
Patch Set: revert accidental revert of sftnly roll during rebase Created 3 years, 9 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.cc ('k') | base/i18n/string_compare.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> 9 #include <memory>
10 10
11 #include "base/format_macros.h" 11 #include "base/format_macros.h"
12 #include "base/i18n/message_formatter.h" 12 #include "base/i18n/message_formatter.h"
13 #include "base/i18n/unicodestring.h"
13 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 17 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "third_party/icu/source/common/unicode/ustring.h" 19 #include "third_party/icu/source/common/unicode/ustring.h"
19 #include "third_party/icu/source/i18n/unicode/numfmt.h" 20 #include "third_party/icu/source/i18n/unicode/numfmt.h"
20 21
21 namespace base { 22 namespace base {
22 23
(...skipping 30 matching lines...) Expand all
53 icu::NumberFormat* number_format = 54 icu::NumberFormat* number_format =
54 g_number_format_int.Get().number_format.get(); 55 g_number_format_int.Get().number_format.get();
55 56
56 if (!number_format) { 57 if (!number_format) {
57 // As a fallback, just return the raw number in a string. 58 // As a fallback, just return the raw number in a string.
58 return ASCIIToUTF16(StringPrintf("%" PRId64, number)); 59 return ASCIIToUTF16(StringPrintf("%" PRId64, number));
59 } 60 }
60 icu::UnicodeString ustr; 61 icu::UnicodeString ustr;
61 number_format->format(number, ustr); 62 number_format->format(number, ustr);
62 63
63 return string16(ustr.getBuffer(), static_cast<size_t>(ustr.length())); 64 return i18n::UnicodeStringToString16(ustr);
64 } 65 }
65 66
66 string16 FormatDouble(double number, int fractional_digits) { 67 string16 FormatDouble(double number, int fractional_digits) {
67 icu::NumberFormat* number_format = 68 icu::NumberFormat* number_format =
68 g_number_format_float.Get().number_format.get(); 69 g_number_format_float.Get().number_format.get();
69 70
70 if (!number_format) { 71 if (!number_format) {
71 // As a fallback, just return the raw number in a string. 72 // As a fallback, just return the raw number in a string.
72 return ASCIIToUTF16(StringPrintf("%f", number)); 73 return ASCIIToUTF16(StringPrintf("%f", number));
73 } 74 }
74 number_format->setMaximumFractionDigits(fractional_digits); 75 number_format->setMaximumFractionDigits(fractional_digits);
75 number_format->setMinimumFractionDigits(fractional_digits); 76 number_format->setMinimumFractionDigits(fractional_digits);
76 icu::UnicodeString ustr; 77 icu::UnicodeString ustr;
77 number_format->format(number, ustr); 78 number_format->format(number, ustr);
78 79
79 return string16(ustr.getBuffer(), static_cast<size_t>(ustr.length())); 80 return i18n::UnicodeStringToString16(ustr);
80 } 81 }
81 82
82 string16 FormatPercent(int number) { 83 string16 FormatPercent(int number) {
83 return i18n::MessageFormatter::FormatWithNumberedArgs( 84 return i18n::MessageFormatter::FormatWithNumberedArgs(
84 ASCIIToUTF16("{0,number,percent}"), static_cast<double>(number) / 100.0); 85 ASCIIToUTF16("{0,number,percent}"), static_cast<double>(number) / 100.0);
85 } 86 }
86 87
87 namespace testing { 88 namespace testing {
88 89
89 void ResetFormatters() { 90 void ResetFormatters() {
90 g_number_format_int.Get().Reset(); 91 g_number_format_int.Get().Reset();
91 g_number_format_float.Get().Reset(); 92 g_number_format_float.Get().Reset();
92 } 93 }
93 94
94 } // namespace testing 95 } // namespace testing
95 96
96 } // namespace base 97 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/message_formatter.cc ('k') | base/i18n/string_compare.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698