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

Unified Diff: base/i18n/number_formatting.cc

Issue 7189076: Localize strings, speeds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: copyright dates Created 9 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: base/i18n/number_formatting.cc
diff --git a/base/i18n/number_formatting.cc b/base/i18n/number_formatting.cc
index a529a84651b9e646261ccfb9a90db5a3115d6b66..1304dbc95bcf579851224065528021805ab97ee0 100644
--- a/base/i18n/number_formatting.cc
+++ b/base/i18n/number_formatting.cc
@@ -20,6 +20,10 @@ namespace {
struct NumberFormatWrapper {
NumberFormatWrapper() {
+ Reset();
+ }
+
+ void Reset() {
// There's no ICU call to destroy a NumberFormat object other than
// operator delete, so use the default Delete, which calls operator delete.
// This can cause problems if a different allocator is used by this file
@@ -34,10 +38,15 @@ struct NumberFormatWrapper {
} // namespace
-static LazyInstance<NumberFormatWrapper> g_number_format(LINKER_INITIALIZED);
+static
Mark Mentovai 2011/06/22 20:24:11 Rather than staticating these, just move them up a
Avi (use Gerrit) 2011/06/22 20:27:37 Done.
+LazyInstance<NumberFormatWrapper> g_number_format_int(LINKER_INITIALIZED);
+
+static
+LazyInstance<NumberFormatWrapper> g_number_format_float(LINKER_INITIALIZED);
string16 FormatNumber(int64 number) {
- icu::NumberFormat* number_format = g_number_format.Get().number_format.get();
+ icu::NumberFormat* number_format =
+ g_number_format_int.Get().number_format.get();
if (!number_format) {
// As a fallback, just return the raw number in a string.
@@ -49,4 +58,29 @@ string16 FormatNumber(int64 number) {
return string16(ustr.getBuffer(), static_cast<size_t>(ustr.length()));
}
+string16 FormatDouble(double number, int fractional_digits) {
+ icu::NumberFormat* number_format =
+ g_number_format_float.Get().number_format.get();
+
+ if (!number_format) {
+ // As a fallback, just return the raw number in a string.
+ return UTF8ToUTF16(StringPrintf("%f", number));
+ }
+ number_format->setMaximumFractionDigits(fractional_digits);
+ number_format->setMinimumFractionDigits(fractional_digits);
+ icu::UnicodeString ustr;
+ number_format->format(number, ustr);
+
+ return string16(ustr.getBuffer(), static_cast<size_t>(ustr.length()));
+}
+
+namespace testing {
+
+void ResetFormatters() {
+ g_number_format_int.Get().Reset();
+ g_number_format_float.Get().Reset();
+}
+
+} // namespace testing
+
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698