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

Unified Diff: base/string_util_icu.cc

Issue 267001: Separate out some more ICU from base and into base/i18n.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
« no previous file with comments | « base/string_util.h ('k') | base/string_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/string_util_icu.cc
===================================================================
--- base/string_util_icu.cc (revision 28217)
+++ base/string_util_icu.cc (working copy)
@@ -1,80 +0,0 @@
-// Copyright (c) 2006-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/string_util.h"
-
-#include <string.h>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/logging.h"
-#include "base/singleton.h"
-#include "unicode/numfmt.h"
-#include "unicode/ustring.h"
-
-// Number formatting -----------------------------------------------------------
-
-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
-
-std::wstring 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 StringPrintf(L"%lld", number);
- }
- icu::UnicodeString ustr;
- number_format->format(number, ustr);
-
-#if defined(WCHAR_T_IS_UTF16)
- return std::wstring(ustr.getBuffer(),
- static_cast<std::wstring::size_type>(ustr.length()));
-#elif defined(WCHAR_T_IS_UTF32)
- wchar_t buffer[64]; // A int64 is less than 20 chars long, so 64 chars
- // leaves plenty of room for formating stuff.
- int length = 0;
- UErrorCode error = U_ZERO_ERROR;
- u_strToWCS(buffer, 64, &length, ustr.getBuffer(), ustr.length() , &error);
- if (U_FAILURE(error)) {
- NOTREACHED();
- // As a fallback, just return the raw number in a string.
- return StringPrintf(L"%lld", number);
- }
- return std::wstring(buffer, static_cast<std::wstring::size_type>(length));
-#endif // defined(WCHAR_T_IS_UTF32)
-}
-
-// Although this function isn't specific to ICU, we implemented it here so
-// that chrome.exe won't pull it in. Moving this function to string_util.cc
-// causes chrome.exe to grow by 400k because of more ICU being pulled in.
-TrimPositions TrimWhitespaceUTF8(const std::string& input,
- TrimPositions positions,
- std::string* output) {
- // This implementation is not so fast since it converts the text encoding
- // twice. Please feel free to file a bug if this function hurts the
- // performance of Chrome.
- DCHECK(IsStringUTF8(input));
- std::wstring input_wide = UTF8ToWide(input);
- std::wstring output_wide;
- TrimPositions result = TrimWhitespace(input_wide, positions, &output_wide);
- *output = WideToUTF8(output_wide);
- return result;
-}
« no previous file with comments | « base/string_util.h ('k') | base/string_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698