summaryrefslogtreecommitdiffstats
path: root/base/i18n/number_formatting.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 17:38:30 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-08 17:38:30 +0000
commitd0767cb54b2b5ee4d9cf00b3ee0fa585826b4036 (patch)
tree1c2ee733bf62a44c31dc11f76dad53243a84439f /base/i18n/number_formatting.cc
parente91d532339c854ff0a082c6562a519647524fa66 (diff)
downloadchromium_src-d0767cb54b2b5ee4d9cf00b3ee0fa585826b4036.zip
chromium_src-d0767cb54b2b5ee4d9cf00b3ee0fa585826b4036.tar.gz
chromium_src-d0767cb54b2b5ee4d9cf00b3ee0fa585826b4036.tar.bz2
Separate out some more ICU from base and into base/i18n.
This moves string_util_icu. I moved the number formatting function into base/i18n/number_formatting and just removed the other function in string_util_icu which was TrimWhitespaceUTF8. It is only used in a few places and isn't actually helpful (and the fact that it round-trips through UTF-16 is better for the caller to see). This takes out the sorting from the FileEnumerator. The comment says the sorting is not guaranteed. I moved it into file_util_icu as a standalone function for callers of FileEnumerator to call manually if they need sorted results. I modified the directory lister to use this sorting instead, and filed a bug on doing more optimal JS-based sorting. TEST=none BUG=none Review URL: http://codereview.chromium.org/267001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28405 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/i18n/number_formatting.cc')
-rw-r--r--base/i18n/number_formatting.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/base/i18n/number_formatting.cc b/base/i18n/number_formatting.cc
new file mode 100644
index 0000000..fef1b7d
--- /dev/null
+++ b/base/i18n/number_formatting.cc
@@ -0,0 +1,48 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/i18n/number_formatting.h"
+
+#include "base/logging.h"
+#include "base/singleton.h"
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
+#include "unicode/numfmt.h"
+#include "unicode/ustring.h"
+
+namespace base {
+
+namespace {
+
+struct NumberFormatSingletonTraits
+ : public DefaultSingletonTraits<icu::NumberFormat> {
+ static icu::NumberFormat* New() {
+ UErrorCode status = U_ZERO_ERROR;
+ icu::NumberFormat* formatter = icu::NumberFormat::createInstance(status);
+ DCHECK(U_SUCCESS(status));
+ return formatter;
+ }
+ // 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 than
+ // by ICU.
+};
+
+} // namespace
+
+string16 FormatNumber(int64 number) {
+ icu::NumberFormat* number_format =
+ Singleton<icu::NumberFormat, NumberFormatSingletonTraits>::get();
+
+ if (!number_format) {
+ // As a fallback, just return the raw number in a string.
+ return UTF8ToUTF16(StringPrintf("%lld", number));
+ }
+ icu::UnicodeString ustr;
+ number_format->format(number, ustr);
+
+ return string16(ustr.getBuffer(), static_cast<size_t>(ustr.length()));
+}
+
+} // namespace base