diff options
30 files changed, 355 insertions, 369 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc index 2afdf2b..854d0a0 100644 --- a/app/l10n_util.cc +++ b/app/l10n_util.cc @@ -11,6 +11,7 @@ #include "app/resource_bundle.h" #include "base/command_line.h" #include "base/file_util.h" +#include "base/i18n/file_util_icu.h" #include "base/path_service.h" #include "base/scoped_ptr.h" #include "base/string16.h" diff --git a/app/os_exchange_data_provider_win.cc b/app/os_exchange_data_provider_win.cc index b407507..997cdee 100644 --- a/app/os_exchange_data_provider_win.cc +++ b/app/os_exchange_data_provider_win.cc @@ -6,7 +6,7 @@ #include "app/clipboard/clipboard_util_win.h" #include "app/l10n_util.h" -#include "base/file_util.h" +#include "base/i18n/file_util_icu.h" #include "base/logging.h" #include "base/pickle.h" #include "base/scoped_handle.h" diff --git a/base/base.gyp b/base/base.gyp index 41108dd..570e9f0 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -121,7 +121,6 @@ 'file_path.h', 'file_util.cc', 'file_util.h', - 'file_util_icu.cc', 'file_util_linux.cc', 'file_util_mac.mm', 'file_util_posix.cc', @@ -141,8 +140,12 @@ 'hmac_mac.cc', 'hmac_nss.cc', 'hmac_win.cc', + 'i18n/file_util_icu.cc', + 'i18n/file_util_icu.h', 'i18n/icu_string_conversions.cc', 'i18n/icu_string_conversions.h', + 'i18n/number_formatting.cc', + 'i18n/number_formatting.h', 'iat_patch.cc', 'iat_patch.h', 'icu_util.cc', @@ -284,7 +287,6 @@ 'string_tokenizer.h', 'string_util.cc', 'string_util.h', - 'string_util_icu.cc', 'string_util_win.h', 'sys_info.h', 'sys_info_chromeos.cc', @@ -582,6 +584,7 @@ 'histogram_unittest.cc', 'hmac_unittest.cc', 'id_map_unittest.cc', + 'i18n/file_util_icu_unittest.cc', 'json_reader_unittest.cc', 'json_writer_unittest.cc', 'lazy_instance_unittest.cc', diff --git a/base/file_util.h b/base/file_util.h index 6474f048..37634b9 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -103,19 +103,6 @@ void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix); void ReplaceExtension(FilePath* file_name, const FilePath::StringType& extension); -// Replaces characters in 'file_name' that are illegal for file names with -// 'replace_char'. 'file_name' must not be a full or relative path, but just the -// file name component. Any leading or trailing whitespace in 'file_name' is -// removed. -// Example: -// file_name == "bad:file*name?.txt", changed to: "bad-file-name-.txt" when -// 'replace_char' is '-'. -void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char); - -// Returns true if file_name does not have any illegal character. The input -// param has the same restriction as that for ReplaceIllegalCharacters. -bool IsFilenameLegal(const string16& file_name); - //----------------------------------------------------------------------------- // Functions that involve filesystem access or modification: @@ -490,10 +477,6 @@ class FileEnumerator { static bool ReadDirectory(std::vector<DirectoryEntryInfo>* entries, const FilePath& source, bool show_links); - // Comparison function to neatly sort directory entries - static bool CompareFiles(const DirectoryEntryInfo& a, - const DirectoryEntryInfo& b); - // The files in the current directory std::vector<DirectoryEntryInfo> directory_entries_; @@ -501,7 +484,7 @@ class FileEnumerator { size_t current_directory_entry_; #endif - DISALLOW_EVIL_CONSTRUCTORS(FileEnumerator); + DISALLOW_COPY_AND_ASSIGN(FileEnumerator); }; class MemoryMappedFile { diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index 27adbfa..4621bb3 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -35,56 +35,6 @@ #include "base/sys_string_conversions.h" #include "base/time.h" #include "base/utf_string_conversions.h" -#include "unicode/coll.h" - - -namespace { - -class LocaleAwareComparator { - public: - LocaleAwareComparator() { - UErrorCode error_code = U_ZERO_ERROR; - // Use the default collator. The default locale should have been properly - // set by the time this constructor is called. - collator_.reset(icu::Collator::createInstance(error_code)); - DCHECK(U_SUCCESS(error_code)); - // Make it case-sensitive. - collator_->setStrength(icu::Collator::TERTIARY); - // Note: We do not set UCOL_NORMALIZATION_MODE attribute. In other words, we - // do not pay performance penalty to guarantee sort order correctness for - // non-FCD (http://unicode.org/notes/tn5/#FCD) file names. This should be a - // reasonable tradeoff because such file names should be rare and the sort - // order doesn't change much anyway. - } - - // Note: A similar function is available in l10n_util. - // We cannot use it because base should not depend on l10n_util. - // TODO(yuzo): Move some of l10n_util to base. - int Compare(const string16& a, const string16& b) { - // We are not sure if Collator::compare is thread-safe. - // Use an AutoLock just in case. - AutoLock auto_lock(lock_); - - UErrorCode error_code = U_ZERO_ERROR; - UCollationResult result = collator_->compare( - static_cast<const UChar*>(a.c_str()), - static_cast<int>(a.length()), - static_cast<const UChar*>(b.c_str()), - static_cast<int>(b.length()), - error_code); - DCHECK(U_SUCCESS(error_code)); - return result; - } - - private: - scoped_ptr<icu::Collator> collator_; - Lock lock_; - friend struct DefaultSingletonTraits<LocaleAwareComparator>; - - DISALLOW_COPY_AND_ASSIGN(LocaleAwareComparator); -}; - -} // namespace namespace file_util { @@ -623,9 +573,6 @@ FilePath FileEnumerator::Next() { if (!ReadDirectory(&entries, root_path_, file_type_ & SHOW_SYM_LINKS)) continue; - // The API says that order is not guaranteed, but order affects UX - std::sort(entries.begin(), entries.end(), CompareFiles); - directory_entries_.clear(); current_directory_entry_ = 0; for (std::vector<DirectoryEntryInfo>::const_iterator @@ -691,23 +638,6 @@ bool FileEnumerator::ReadDirectory(std::vector<DirectoryEntryInfo>* entries, return true; } -bool FileEnumerator::CompareFiles(const DirectoryEntryInfo& a, - const DirectoryEntryInfo& b) { - // Order lexicographically with directories before other files. - if (S_ISDIR(a.stat.st_mode) != S_ISDIR(b.stat.st_mode)) - return S_ISDIR(a.stat.st_mode); - - // On linux, the file system encoding is not defined. We assume - // SysNativeMBToWide takes care of it. - // - // ICU's collator can take strings in OS native encoding. But we convert the - // strings to UTF-16 ourselves to ensure conversion consistency. - // TODO(yuzo): Perhaps we should define SysNativeMBToUTF16? - return Singleton<LocaleAwareComparator>()->Compare( - WideToUTF16(base::SysNativeMBToWide(a.filename.value().c_str())), - WideToUTF16(base::SysNativeMBToWide(b.filename.value().c_str()))) < 0; -} - /////////////////////////////////////////////// // MemoryMappedFile diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index 5b606c9..b1f9fed 100644 --- a/base/file_util_unittest.cc +++ b/base/file_util_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -876,41 +876,6 @@ TEST_F(FileUtilTest, DetectDirectoryTest) { EXPECT_TRUE(file_util::Delete(test_root, true)); } -static const struct goodbad_pair { - std::wstring bad_name; - std::wstring good_name; -} kIllegalCharacterCases[] = { - {L"bad*file:name?.jpg", L"bad-file-name-.jpg"}, - {L"**********::::.txt", L"--------------.txt"}, - // We can't use UCNs (universal character names) for C0/C1 characters and - // U+007F, but \x escape is interpreted by MSVC and gcc as we intend. - {L"bad\x0003\x0091 file\u200E\u200Fname.png", L"bad-- file--name.png"}, -#if defined(OS_WIN) - {L"bad*file\\name.jpg", L"bad-file-name.jpg"}, - {L"\t bad*file\\name/.jpg ", L"bad-file-name-.jpg"}, -#elif defined(OS_POSIX) - {L"bad*file?name.jpg", L"bad-file-name.jpg"}, - {L"\t bad*file?name/.jpg ", L"bad-file-name-.jpg"}, -#endif - {L"this_file_name is okay!.mp3", L"this_file_name is okay!.mp3"}, - {L"\u4E00\uAC00.mp3", L"\u4E00\uAC00.mp3"}, - {L"\u0635\u200C\u0644.mp3", L"\u0635\u200C\u0644.mp3"}, - {L"\U00010330\U00010331.mp3", L"\U00010330\U00010331.mp3"}, - // Unassigned codepoints are ok. - {L"\u0378\U00040001.mp3", L"\u0378\U00040001.mp3"}, - // Non-characters are not allowed. - {L"bad\uFFFFfile\U0010FFFEname.jpg ", L"bad-file-name.jpg"}, - {L"bad\uFDD0file\uFDEFname.jpg ", L"bad-file-name.jpg"}, -}; - -TEST_F(FileUtilTest, ReplaceIllegalCharactersTest) { - for (unsigned int i = 0; i < arraysize(kIllegalCharacterCases); ++i) { - std::wstring bad_name(kIllegalCharacterCases[i].bad_name); - file_util::ReplaceIllegalCharacters(&bad_name, L'-'); - EXPECT_EQ(kIllegalCharacterCases[i].good_name, bad_name); - } -} - static const struct ReplaceExtensionCase { std::wstring file_name; FilePath::StringType extension; @@ -1069,58 +1034,6 @@ TEST_F(FileUtilTest, FileEnumeratorTest) { // (we don't care what). } -TEST_F(FileUtilTest, FileEnumeratorOrderTest) { - FilePath fileA = test_dir_.Append(FILE_PATH_LITERAL("a")); - FilePath fileB = test_dir_.Append(FILE_PATH_LITERAL("B")); - FilePath dirC = test_dir_.Append(FILE_PATH_LITERAL("C")); - FilePath dirD = test_dir_.Append(FILE_PATH_LITERAL("d")); - FilePath dirE = test_dir_.Append(FILE_PATH_LITERAL("e")); - FilePath fileF = test_dir_.Append(FILE_PATH_LITERAL("f")); - - // Create files/directories in near random order. - CreateTextFile(fileF, L""); - CreateTextFile(fileA, L""); - CreateTextFile(fileB, L""); - EXPECT_TRUE(file_util::CreateDirectory(dirE)); - EXPECT_TRUE(file_util::CreateDirectory(dirC)); - EXPECT_TRUE(file_util::CreateDirectory(dirD)); - - // On Windows, files and directories are enumerated in the lexicographical - // order, ignoring case and whether they are files or directories. On posix, - // we order directories before files. - file_util::FileEnumerator enumerator(test_dir_, false, FILES_AND_DIRECTORIES); - FilePath cur_file = enumerator.Next(); -#if defined(OS_WIN) - EXPECT_EQ(fileA.value(), cur_file.value()); - cur_file = enumerator.Next(); - EXPECT_EQ(fileB.value(), cur_file.value()); - cur_file = enumerator.Next(); - EXPECT_EQ(dirC.value(), cur_file.value()); - cur_file = enumerator.Next(); - EXPECT_EQ(dirD.value(), cur_file.value()); - cur_file = enumerator.Next(); - EXPECT_EQ(dirE.value(), cur_file.value()); - cur_file = enumerator.Next(); - EXPECT_EQ(fileF.value(), cur_file.value()); - cur_file = enumerator.Next(); -#elif defined(OS_POSIX) - EXPECT_EQ(dirC.value(), cur_file.value()); - cur_file = enumerator.Next(); - EXPECT_EQ(dirD.value(), cur_file.value()); - cur_file = enumerator.Next(); - EXPECT_EQ(dirE.value(), cur_file.value()); - cur_file = enumerator.Next(); - EXPECT_EQ(fileA.value(), cur_file.value()); - cur_file = enumerator.Next(); - EXPECT_EQ(fileB.value(), cur_file.value()); - cur_file = enumerator.Next(); - EXPECT_EQ(fileF.value(), cur_file.value()); - cur_file = enumerator.Next(); -#endif - - EXPECT_EQ(FILE_PATH_LITERAL(""), cur_file.value()); -} - TEST_F(FileUtilTest, Contains) { FilePath data_dir = test_dir_.Append(FILE_PATH_LITERAL("FilePathTest")); diff --git a/base/file_util_icu.cc b/base/i18n/file_util_icu.cc index eeffa92..0bc9db6 100644 --- a/base/file_util_icu.cc +++ b/base/i18n/file_util_icu.cc @@ -2,21 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// File utilities that use the ICU library go in this file. Functions using ICU -// are separated from the other functions to prevent ICU being pulled in by the -// linker if there is a false dependency. -// -// (The VS2005 linker finds such a false dependency and adds ~300K of ICU to -// chrome.exe if this code lives in file_util.cc, even though none of this code -// is called.) +// File utilities that use the ICU library go in this file. -#include "base/file_util.h" +#include "base/i18n/file_util_icu.h" +#include "base/file_path.h" +#include "base/scoped_ptr.h" #include "base/singleton.h" #include "base/string_util.h" +#include "base/sys_string_conversions.h" +#include "build/build_config.h" +#include "unicode/coll.h" #include "unicode/uniset.h" namespace { + class IllegalCharacters { public: bool contains(UChar32 ucs4) { @@ -72,6 +72,50 @@ IllegalCharacters::IllegalCharacters() { set->freeze(); } +class LocaleAwareComparator { + public: + LocaleAwareComparator() { + UErrorCode error_code = U_ZERO_ERROR; + // Use the default collator. The default locale should have been properly + // set by the time this constructor is called. + collator_.reset(icu::Collator::createInstance(error_code)); + DCHECK(U_SUCCESS(error_code)); + // Make it case-sensitive. + collator_->setStrength(icu::Collator::TERTIARY); + // Note: We do not set UCOL_NORMALIZATION_MODE attribute. In other words, we + // do not pay performance penalty to guarantee sort order correctness for + // non-FCD (http://unicode.org/notes/tn5/#FCD) file names. This should be a + // reasonable tradeoff because such file names should be rare and the sort + // order doesn't change much anyway. + } + + // Note: A similar function is available in l10n_util. + // We cannot use it because base should not depend on l10n_util. + // TODO(yuzo): Move some of l10n_util to base. + int Compare(const string16& a, const string16& b) { + // We are not sure if Collator::compare is thread-safe. + // Use an AutoLock just in case. + AutoLock auto_lock(lock_); + + UErrorCode error_code = U_ZERO_ERROR; + UCollationResult result = collator_->compare( + static_cast<const UChar*>(a.c_str()), + static_cast<int>(a.length()), + static_cast<const UChar*>(b.c_str()), + static_cast<int>(b.length()), + error_code); + DCHECK(U_SUCCESS(error_code)); + return result; + } + + private: + scoped_ptr<icu::Collator> collator_; + Lock lock_; + friend struct DefaultSingletonTraits<LocaleAwareComparator>; + + DISALLOW_COPY_AND_ASSIGN(LocaleAwareComparator); +}; + } // namespace namespace file_util { @@ -126,4 +170,24 @@ void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char) { #endif } +bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) { +#if defined(OS_WIN) + return Singleton<LocaleAwareComparator>()->Compare(a.value().c_str(), + b.value().c_str()) < 0; + +#elif defined(OS_POSIX) + // On linux, the file system encoding is not defined. We assume + // SysNativeMBToWide takes care of it. + // + // ICU's collator can take strings in OS native encoding. But we convert the + // strings to UTF-16 ourselves to ensure conversion consistency. + // TODO(yuzo): Perhaps we should define SysNativeMBToUTF16? + return Singleton<LocaleAwareComparator>()->Compare( + WideToUTF16(base::SysNativeMBToWide(a.value().c_str())), + WideToUTF16(base::SysNativeMBToWide(b.value().c_str()))) < 0; +#else + #error Not implemented on your system +#endif +} + } // namespace diff --git a/base/i18n/file_util_icu.h b/base/i18n/file_util_icu.h new file mode 100644 index 0000000..c309a9e --- /dev/null +++ b/base/i18n/file_util_icu.h @@ -0,0 +1,33 @@ +// Copyright (c) 2009 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. + +// File utilities that use the ICU library go in this file. + +#include <string> + +#include "base/string16.h" + +class FilePath; + +namespace file_util { + +// Returns true if file_name does not have any illegal character. The input +// param has the same restriction as that for ReplaceIllegalCharacters. +bool IsFilenameLegal(const string16& file_name); + +// Replaces characters in 'file_name' that are illegal for file names with +// 'replace_char'. 'file_name' must not be a full or relative path, but just the +// file name component. Any leading or trailing whitespace in 'file_name' is +// removed. +// Example: +// file_name == "bad:file*name?.txt", changed to: "bad-file-name-.txt" when +// 'replace_char' is '-'. +void ReplaceIllegalCharacters(std::wstring* file_name, int replace_char); + +// Compares two filenames using the current locale information. This can be +// used to sort directory listings. It behaves like "operator<" for use in +// std::sort. +bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b); + +} // namespace file_util diff --git a/base/i18n/file_util_icu_unittest.cc b/base/i18n/file_util_icu_unittest.cc new file mode 100644 index 0000000..aebcd0df --- /dev/null +++ b/base/i18n/file_util_icu_unittest.cc @@ -0,0 +1,71 @@ +// Copyright (c) 2009 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/file_util_icu.h" + +#include "base/file_util.h" +#include "base/path_service.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/platform_test.h" + +// file_util winds up using autoreleased objects on the Mac, so this needs +// to be a PlatformTest +class FileUtilICUTest : public PlatformTest { + protected: + virtual void SetUp() { + PlatformTest::SetUp(); + // Name a subdirectory of the temp directory. + ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); + test_dir_ = test_dir_.Append(FILE_PATH_LITERAL("FileUtilTest")); + + // Create a fresh, empty copy of this directory. + file_util::Delete(test_dir_, true); + file_util::CreateDirectory(test_dir_); + } + virtual void TearDown() { + PlatformTest::TearDown(); + // Clean up test directory + ASSERT_TRUE(file_util::Delete(test_dir_, true)); + ASSERT_FALSE(file_util::PathExists(test_dir_)); + } + + // the path to temporary directory used to contain the test operations + FilePath test_dir_; +}; + +static const struct goodbad_pair { + std::wstring bad_name; + std::wstring good_name; +} kIllegalCharacterCases[] = { + {L"bad*file:name?.jpg", L"bad-file-name-.jpg"}, + {L"**********::::.txt", L"--------------.txt"}, + // We can't use UCNs (universal character names) for C0/C1 characters and + // U+007F, but \x escape is interpreted by MSVC and gcc as we intend. + {L"bad\x0003\x0091 file\u200E\u200Fname.png", L"bad-- file--name.png"}, +#if defined(OS_WIN) + {L"bad*file\\name.jpg", L"bad-file-name.jpg"}, + {L"\t bad*file\\name/.jpg ", L"bad-file-name-.jpg"}, +#elif defined(OS_POSIX) + {L"bad*file?name.jpg", L"bad-file-name.jpg"}, + {L"\t bad*file?name/.jpg ", L"bad-file-name-.jpg"}, +#endif + {L"this_file_name is okay!.mp3", L"this_file_name is okay!.mp3"}, + {L"\u4E00\uAC00.mp3", L"\u4E00\uAC00.mp3"}, + {L"\u0635\u200C\u0644.mp3", L"\u0635\u200C\u0644.mp3"}, + {L"\U00010330\U00010331.mp3", L"\U00010330\U00010331.mp3"}, + // Unassigned codepoints are ok. + {L"\u0378\U00040001.mp3", L"\u0378\U00040001.mp3"}, + // Non-characters are not allowed. + {L"bad\uFFFFfile\U0010FFFEname.jpg ", L"bad-file-name.jpg"}, + {L"bad\uFDD0file\uFDEFname.jpg ", L"bad-file-name.jpg"}, +}; + +TEST_F(FileUtilICUTest, ReplaceIllegalCharactersTest) { + for (unsigned int i = 0; i < arraysize(kIllegalCharacterCases); ++i) { + std::wstring bad_name(kIllegalCharacterCases[i].bad_name); + file_util::ReplaceIllegalCharacters(&bad_name, L'-'); + EXPECT_EQ(kIllegalCharacterCases[i].good_name, bad_name); + } +} + 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 diff --git a/base/i18n/number_formatting.h b/base/i18n/number_formatting.h new file mode 100644 index 0000000..9fa2b18 --- /dev/null +++ b/base/i18n/number_formatting.h @@ -0,0 +1,19 @@ +// 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. + +#ifndef BASE_I18N_NUMBER_FORMATTING_H_ +#define BASE_I18N_NUMBER_FORMATTING_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/string16.h" + +namespace base { + +string16 FormatNumber(int64 number); + +} // namespace base + +#endif // BASE_I18N_NUMBER_FORMATTING_H_ diff --git a/base/string_util.h b/base/string_util.h index 254e18f..c6b9fb1 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -140,8 +140,6 @@ bool TrimString(const std::string& input, // The non-wide version has two functions: // * TrimWhitespaceASCII() // This function is for ASCII strings and only looks for ASCII whitespace; -// * TrimWhitespaceUTF8() -// This function is for UTF-8 strings and looks for Unicode whitespace. // Please choose the best one according to your usage. // NOTE: Safe to use the same variable for both input and output. enum TrimPositions { @@ -156,9 +154,6 @@ TrimPositions TrimWhitespace(const std::wstring& input, TrimPositions TrimWhitespaceASCII(const std::string& input, TrimPositions positions, std::string* output); -TrimPositions TrimWhitespaceUTF8(const std::string& input, - TrimPositions positions, - std::string* output); // Deprecated. This function is only for backward compatibility and calls // TrimWhitespaceASCII(). diff --git a/base/string_util_icu.cc b/base/string_util_icu.cc deleted file mode 100644 index 68fbd10..0000000 --- a/base/string_util_icu.cc +++ /dev/null @@ -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; -} diff --git a/base/string_util_unittest.cc b/base/string_util_unittest.cc index 2723541..a70b03e 100644 --- a/base/string_util_unittest.cc +++ b/base/string_util_unittest.cc @@ -100,52 +100,6 @@ TEST(StringUtilTest, TrimWhitespace) { } } -static const struct trim_case_utf8 { - const char* input; - const TrimPositions positions; - const char* output; - const TrimPositions return_value; -} trim_cases_utf8[] = { - // UTF-8 strings that start (and end) with Unicode space characters - // (including zero-width spaces). - {"\xE2\x80\x80Test String\xE2\x80\x81", TRIM_ALL, "Test String", TRIM_ALL}, - {"\xE2\x80\x82Test String\xE2\x80\x83", TRIM_ALL, "Test String", TRIM_ALL}, - {"\xE2\x80\x84Test String\xE2\x80\x85", TRIM_ALL, "Test String", TRIM_ALL}, - {"\xE2\x80\x86Test String\xE2\x80\x87", TRIM_ALL, "Test String", TRIM_ALL}, - {"\xE2\x80\x88Test String\xE2\x80\x8A", TRIM_ALL, "Test String", TRIM_ALL}, - {"\xE3\x80\x80Test String\xE3\x80\x80", TRIM_ALL, "Test String", TRIM_ALL}, - // UTF-8 strings that end with 0x85 (NEL in ISO-8859). - {"\xD0\x85", TRIM_TRAILING, "\xD0\x85", TRIM_NONE}, - {"\xD9\x85", TRIM_TRAILING, "\xD9\x85", TRIM_NONE}, - {"\xEC\x97\x85", TRIM_TRAILING, "\xEC\x97\x85", TRIM_NONE}, - {"\xF0\x90\x80\x85", TRIM_TRAILING, "\xF0\x90\x80\x85", TRIM_NONE}, - // UTF-8 strings that end with 0xA0 (non-break space in ISO-8859-1). - {"\xD0\xA0", TRIM_TRAILING, "\xD0\xA0", TRIM_NONE}, - {"\xD9\xA0", TRIM_TRAILING, "\xD9\xA0", TRIM_NONE}, - {"\xEC\x97\xA0", TRIM_TRAILING, "\xEC\x97\xA0", TRIM_NONE}, - {"\xF0\x90\x80\xA0", TRIM_TRAILING, "\xF0\x90\x80\xA0", TRIM_NONE}, -}; - -TEST(StringUtilTest, TrimWhitespaceUTF8) { - std::string output_ascii; - for (size_t i = 0; i < arraysize(trim_cases_ascii); ++i) { - const trim_case_ascii& value = trim_cases_ascii[i]; - EXPECT_EQ(value.return_value, - TrimWhitespaceASCII(value.input, value.positions, &output_ascii)); - EXPECT_EQ(value.output, output_ascii); - } - - // Test that TrimWhiteSpaceUTF8() can remove Unicode space characters and - // prevent from removing UTF-8 characters that end with an ISO-8859 NEL. - std::string output_utf8; - for (size_t i = 0; i < arraysize(trim_cases_utf8); ++i) { - const trim_case_utf8& value = trim_cases_utf8[i]; - EXPECT_EQ(value.return_value, - TrimWhitespaceUTF8(value.input, value.positions, &output_utf8)); - EXPECT_EQ(value.output, output_utf8); - } -} - static const struct collapse_case { const wchar_t* input; const bool trim; diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index 6a2989e..47b3160 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -8,6 +8,7 @@ #include "app/l10n_util.h" #include "base/basictypes.h" +#include "base/i18n/number_formatting.h" #include "base/string_util.h" #include "chrome/browser/autocomplete/history_url_provider.h" #include "chrome/browser/autocomplete/history_contents_provider.h" @@ -879,12 +880,12 @@ void AutocompleteController::AddHistoryContentsShortcut() { } else { // We can report exact matches when there aren't too many. std::vector<size_t> content_param_offsets; - match.contents = - l10n_util::GetStringF(IDS_OMNIBOX_RECENT_HISTORY, - FormatNumber(history_contents_provider_-> - db_match_count()), - input_.text(), - &content_param_offsets); + match.contents = l10n_util::GetStringF( + IDS_OMNIBOX_RECENT_HISTORY, + UTF16ToWide(base::FormatNumber(history_contents_provider_-> + db_match_count())), + input_.text(), + &content_param_offsets); // content_param_offsets is ordered based on supplied params, we expect // that the second one contains the query (first is the number). diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index 5a907c5..9c07143 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -11,6 +11,7 @@ #include "app/resource_bundle.h" #include "base/file_version_info.h" #include "base/histogram.h" +#include "base/i18n/number_formatting.h" #include "base/path_service.h" #include "base/platform_thread.h" #include "base/stats_table.h" @@ -482,7 +483,7 @@ static void AddIntSyncDetail(ListValue* details, const std::wstring& stat_name, int64 stat_value) { DictionaryValue* val = new DictionaryValue; val->SetString(L"stat_name", stat_name); - val->SetString(L"stat_value", FormatNumber(stat_value)); + val->SetString(L"stat_value", UTF16ToWide(base::FormatNumber(stat_value))); details->Append(val); } diff --git a/chrome/browser/download/download_item_model.cc b/chrome/browser/download/download_item_model.cc index 3ac8d3d..cca2169 100644 --- a/chrome/browser/download/download_item_model.cc +++ b/chrome/browser/download/download_item_model.cc @@ -1,10 +1,11 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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 "chrome/browser/download/download_item_model.h" #include "app/l10n_util.h" +#include "base/i18n/number_formatting.h" #include "base/string_util.h" #include "chrome/browser/download/download_manager.h" #include "chrome/browser/download/save_package.h" @@ -110,9 +111,10 @@ std::wstring SavePageModel::GetStatusText() { std::wstring status_text; switch (download_->state()) { case DownloadItem::IN_PROGRESS: - status_text = l10n_util::GetStringF(IDS_SAVE_PAGE_PROGRESS, - FormatNumber(size), - FormatNumber(total_size)); + status_text = l10n_util::GetStringF( + IDS_SAVE_PAGE_PROGRESS, + UTF16ToWide(base::FormatNumber(size)), + UTF16ToWide(base::FormatNumber(total_size))); break; case DownloadItem::COMPLETE: status_text = l10n_util::GetString(IDS_SAVE_PAGE_STATUS_COMPLETED); diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc index 33c8bfb..1b9eaa9 100644 --- a/chrome/browser/download/save_package.cc +++ b/chrome/browser/download/save_package.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -6,6 +6,7 @@ #include "app/l10n_util.h" #include "base/file_util.h" +#include "base/i18n/file_util_icu.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/stl_util-inl.h" diff --git a/chrome/browser/net/url_fixer_upper.cc b/chrome/browser/net/url_fixer_upper.cc index 498bd6c..b276e02 100644 --- a/chrome/browser/net/url_fixer_upper.cc +++ b/chrome/browser/net/url_fixer_upper.cc @@ -70,6 +70,20 @@ void UTF8PartsToWideParts(const string& text_utf8, UTF8ComponentToWideComponent(text_utf8, parts_utf8.ref); } +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; +} + } // namespace // does some basic fixes for input that we want to test for file-ness diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc index 3034afb..93aed21 100644 --- a/chrome/browser/shell_integration_linux.cc +++ b/chrome/browser/shell_integration_linux.cc @@ -18,6 +18,7 @@ #include "base/eintr_wrapper.h" #include "base/file_path.h" #include "base/file_util.h" +#include "base/i18n/file_util_icu.h" #include "base/message_loop.h" #include "base/path_service.h" #include "base/process_util.h" diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc index d01e94f..0af61ff 100644 --- a/chrome/browser/task_manager.cc +++ b/chrome/browser/task_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -7,6 +7,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/compiler_specific.h" +#include "base/i18n/number_formatting.h" #include "base/process_util.h" #include "base/stats_table.h" #include "base/string_util.h" @@ -128,8 +129,7 @@ std::wstring TaskManagerModel::GetResourcePrivateMemory(int index) const { metrics_map_.find(resources_[index]->GetProcess()); DCHECK(iter != metrics_map_.end()); base::ProcessMetrics* process_metrics = iter->second; - std::wstring number = FormatNumber(GetPrivateMemory(process_metrics)); - return GetMemCellText(&number); + return GetMemCellText(GetPrivateMemory(process_metrics)); } std::wstring TaskManagerModel::GetResourceSharedMemory(int index) const { @@ -138,8 +138,7 @@ std::wstring TaskManagerModel::GetResourceSharedMemory(int index) const { metrics_map_.find(resources_[index]->GetProcess()); DCHECK(iter != metrics_map_.end()); base::ProcessMetrics* process_metrics = iter->second; - std::wstring number = FormatNumber(GetSharedMemory(process_metrics)); - return GetMemCellText(&number); + return GetMemCellText(GetSharedMemory(process_metrics)); } std::wstring TaskManagerModel::GetResourcePhysicalMemory(int index) const { @@ -148,8 +147,7 @@ std::wstring TaskManagerModel::GetResourcePhysicalMemory(int index) const { metrics_map_.find(resources_[index]->GetProcess()); DCHECK(iter != metrics_map_.end()); base::ProcessMetrics* process_metrics = iter->second; - std::wstring number = FormatNumber(GetPhysicalMemory(process_metrics)); - return GetMemCellText(&number); + return GetMemCellText(GetPhysicalMemory(process_metrics)); } std::wstring TaskManagerModel::GetResourceProcessId(int index) const { @@ -166,7 +164,7 @@ std::wstring TaskManagerModel::GetResourceStatsValue(int index, int col_id) std::wstring TaskManagerModel::GetResourceGoatsTeleported(int index) const { DCHECK(index < ResourceCount()); goats_teleported_ += rand() & 4095; - return FormatNumber(goats_teleported_); + return UTF16ToWide(base::FormatNumber(goats_teleported_)); } std::wstring TaskManagerModel::GetResourceWebCoreImageCacheSize( @@ -385,11 +383,12 @@ int TaskManagerModel::GetStatsValue(const TaskManager::Resource* resource, return 0; } -std::wstring TaskManagerModel::GetMemCellText( - std::wstring* number) const { +std::wstring TaskManagerModel::GetMemCellText(int64 number) const { + std::wstring str = UTF16ToWide(base::FormatNumber(number)); + // Adjust number string if necessary. - l10n_util::AdjustStringForLocaleDirection(*number, number); - return l10n_util::GetStringF(IDS_TASK_MANAGER_MEM_CELL_TEXT, *number); + l10n_util::AdjustStringForLocaleDirection(str, &str); + return l10n_util::GetStringF(IDS_TASK_MANAGER_MEM_CELL_TEXT, str); } void TaskManagerModel::StartUpdating() { diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h index ff402a4..a4ece90 100644 --- a/chrome/browser/task_manager.h +++ b/chrome/browser/task_manager.h @@ -315,9 +315,9 @@ class TaskManagerModel : public URLRequestJobTracker::JobObserver, base::ProcessMetrics** proc_metrics1, base::ProcessMetrics** proc_metrics2) const; - // Given a string containing a number, this function returns the formatted - // string that should be displayed in the task manager's memory cell. - std::wstring GetMemCellText(std::wstring* number) const; + // Given a number, this function returns the formatted string that should be + // displayed in the task manager's memory cell. + std::wstring GetMemCellText(int64 number) const; // The list of providers to the task manager. They are ref counted. ResourceProviderList providers_; diff --git a/chrome/browser/views/new_profile_dialog.cc b/chrome/browser/views/new_profile_dialog.cc index c3b12bb..f0cfded 100644 --- a/chrome/browser/views/new_profile_dialog.cc +++ b/chrome/browser/views/new_profile_dialog.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -9,7 +9,7 @@ #include "app/l10n_util.h" #include "app/message_box_flags.h" #include "base/logging.h" -#include "base/file_util.h" +#include "base/i18n/file_util_icu.h" #include "chrome/browser/user_data_manager.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" diff --git a/chrome/tools/convert_dict/hunspell_reader.cc b/chrome/tools/convert_dict/hunspell_reader.cc index 52e3117..b573b1c 100644 --- a/chrome/tools/convert_dict/hunspell_reader.cc +++ b/chrome/tools/convert_dict/hunspell_reader.cc @@ -20,7 +20,10 @@ void TrimLine(std::string* line) { static_cast<unsigned char>((*line)[2]) == 0xbf) *line = line->substr(3); - TrimWhitespaceUTF8(*line, TRIM_ALL, line); + std::wstring line_input_wide = UTF8ToWide(*line); + std::wstring line_output_wide; + TrimWhitespace(line_input_wide, TRIM_ALL, &line_output_wide); + *line = WideToUTF8(line_output_wide); } std::string ReadLine(FILE* file) { diff --git a/net/base/directory_lister.cc b/net/base/directory_lister.cc index 616fc82..7ea862f 100644 --- a/net/base/directory_lister.cc +++ b/net/base/directory_lister.cc @@ -1,10 +1,14 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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 "net/base/directory_lister.h" +#include <algorithm> +#include <vector> + #include "base/file_util.h" +#include "base/i18n/file_util_icu.h" #include "base/message_loop.h" #include "base/platform_thread.h" #include "net/base/net_errors.h" @@ -15,23 +19,37 @@ static const int kFilesPerEvent = 8; class DirectoryDataEvent : public Task { public: - explicit DirectoryDataEvent(DirectoryLister* d) - : lister(d), count(0), error(0) { + explicit DirectoryDataEvent(DirectoryLister* d) : lister(d), error(0) { + // Allocations of the FindInfo aren't super cheap, so reserve space. + data.reserve(64); } void Run() { - if (count) { - lister->OnReceivedData(data, count); - } else { + if (data.empty()) { lister->OnDone(error); + return; } + lister->OnReceivedData(&data[0], static_cast<int>(data.size())); } scoped_refptr<DirectoryLister> lister; - file_util::FileEnumerator::FindInfo data[kFilesPerEvent]; - int count, error; + std::vector<file_util::FileEnumerator::FindInfo> data; + int error; }; +// Comparator for sorting FindInfo's. This uses the locale aware filename +// comparison function on the filenames for sorting in the user's locale. +static bool CompareFindInfo(const file_util::FileEnumerator::FindInfo& a, + const file_util::FileEnumerator::FindInfo& b) { +#if defined(OS_WIN) + return file_util::LocaleAwareCompareFilenames(FilePath(a.cFileName), + FilePath(b.cFileName)); +#elif defined(OS_POSIX) + return file_util::LocaleAwareCompareFilenames(FilePath(a.filename), + FilePath(b.filename)); +#endif +} + DirectoryLister::DirectoryLister(const FilePath& dir, DirectoryListerDelegate* delegate) : dir_(dir), @@ -91,15 +109,25 @@ void DirectoryLister::ThreadMain() { file_util::FileEnumerator::INCLUDE_DOT_DOT)); while (!canceled_ && !(file_enum.Next().value().empty())) { - file_enum.GetFindInfo(&e->data[e->count]); + e->data.push_back(file_util::FileEnumerator::FindInfo()); + file_enum.GetFindInfo(&e->data[e->data.size() - 1]); + /* TODO(brettw) bug 24107: It would be nice to send incremental updates. + We gather them all so they can be sorted, but eventually the sorting + should be done from JS to give more flexibility in the page. When we do + that, we can uncomment this to send incremental updates to the page. if (++e->count == kFilesPerEvent) { message_loop_->PostTask(FROM_HERE, e); e = new DirectoryDataEvent(this); } + */ } - if (e->count > 0) { + if (!e->data.empty()) { + // Sort the results. See the TODO above (this sort should be removed and we + // should do it from JS). + std::sort(e->data.begin(), e->data.end(), CompareFindInfo); + message_loop_->PostTask(FROM_HERE, e); e = new DirectoryDataEvent(this); } diff --git a/net/base/directory_lister.h b/net/base/directory_lister.h index cb98da6..27204b6 100644 --- a/net/base/directory_lister.h +++ b/net/base/directory_lister.h @@ -1,9 +1,9 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. -#ifndef NET_BASE_DIRECTORY_LISTER_H__ -#define NET_BASE_DIRECTORY_LISTER_H__ +#ifndef NET_BASE_DIRECTORY_LISTER_H_ +#define NET_BASE_DIRECTORY_LISTER_H_ #include <string> @@ -68,4 +68,4 @@ class DirectoryLister : public base::RefCountedThreadSafe<DirectoryLister>, } // namespace net -#endif // NET_BASE_DIRECTORY_LISTER_H__ +#endif // NET_BASE_DIRECTORY_LISTER_H_ diff --git a/net/base/net_util.cc b/net/base/net_util.cc index b484b0c..8c36a5f 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -29,6 +29,7 @@ #include "base/basictypes.h" #include "base/file_path.h" #include "base/file_util.h" +#include "base/i18n/file_util_icu.h" #include "base/lock.h" #include "base/logging.h" #include "base/message_loop.h" diff --git a/printing/printed_document.cc b/printing/printed_document.cc index 918c99e..0864d4b 100644 --- a/printing/printed_document.cc +++ b/printing/printed_document.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -9,6 +9,7 @@ #include "app/gfx/font.h" #include "app/gfx/text_elider.h" #include "base/file_util.h" +#include "base/i18n/file_util_icu.h" #include "base/message_loop.h" #include "base/singleton.h" #include "base/string_util.h" diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc index 8706b05..c924f06 100644 --- a/printing/printing_context_win.cc +++ b/printing/printing_context_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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. @@ -7,6 +7,7 @@ #include <winspool.h> #include "base/file_util.h" +#include "base/i18n/file_util_icu.h" #include "base/message_loop.h" #include "base/time.h" #include "base/time_format.h" diff --git a/webkit/glue/webplugin_impl.cc b/webkit/glue/webplugin_impl.cc index 6c48b56..22ba10b 100644 --- a/webkit/glue/webplugin_impl.cc +++ b/webkit/glue/webplugin_impl.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "net/base/escape.h" #include "skia/ext/platform_canvas.h" #include "webkit/api/public/WebConsoleMessage.h" @@ -150,9 +151,7 @@ std::string GetAllHeaders(const WebURLResponse& response) { return result; // TODO(darin): Shouldn't we also report HTTP version numbers? - result.append("HTTP "); - result.append(WideToUTF8(FormatNumber(response.httpStatusCode()))); - result.append(" "); + result = StringPrintf("HTTP %d ", response.httpStatusCode()); result.append(status.utf8()); result.append("\n"); |