diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-07 23:59:15 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-07 23:59:15 +0000 |
commit | 6bc03dea3c8fe7578a19d0a31bfdc123bc3198c6 (patch) | |
tree | bab7a1efa04e0bf9945085ce6ca3dab2ef85c51f | |
parent | f09c1ddad8c111d0b678ad36393785a30d1ebcf0 (diff) | |
download | chromium_src-6bc03dea3c8fe7578a19d0a31bfdc123bc3198c6.zip chromium_src-6bc03dea3c8fe7578a19d0a31bfdc123bc3198c6.tar.gz chromium_src-6bc03dea3c8fe7578a19d0a31bfdc123bc3198c6.tar.bz2 |
Move file_util_icu to base::i18n namespace
TBR=sky
Review URL: https://codereview.chromium.org/447403002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288170 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/i18n/file_util_icu.cc | 36 | ||||
-rw-r--r-- | base/i18n/file_util_icu.h | 16 | ||||
-rw-r--r-- | base/i18n/file_util_icu_unittest.cc | 25 | ||||
-rw-r--r-- | chrome/browser/download/save_package_file_picker.cc | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/api/bookmarks/bookmarks_api.cc | 2 | ||||
-rw-r--r-- | chrome/browser/shell_integration_linux.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/webui/print_preview/print_preview_handler.cc | 2 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app.cc | 4 | ||||
-rw-r--r-- | content/browser/download/save_package.cc | 2 | ||||
-rw-r--r-- | net/base/directory_lister.cc | 6 | ||||
-rw-r--r-- | net/base/directory_lister_unittest.cc | 4 | ||||
-rw-r--r-- | net/base/filename_util_icu.cc | 8 | ||||
-rw-r--r-- | printing/printed_document.cc | 2 | ||||
-rw-r--r-- | ui/base/dragdrop/os_exchange_data_provider_win.cc | 2 | ||||
-rw-r--r-- | ui/base/l10n/l10n_util.cc | 2 |
15 files changed, 62 insertions, 57 deletions
diff --git a/base/i18n/file_util_icu.cc b/base/i18n/file_util_icu.cc index e250c29..b5c0b9d 100644 --- a/base/i18n/file_util_icu.cc +++ b/base/i18n/file_util_icu.cc @@ -19,7 +19,8 @@ #include "third_party/icu/source/common/unicode/uniset.h" #include "third_party/icu/source/i18n/unicode/coll.h" -using base::string16; +namespace base { +namespace i18n { namespace { @@ -84,20 +85,18 @@ IllegalCharacters::IllegalCharacters() { } // namespace -namespace file_util { - bool IsFilenameLegal(const string16& file_name) { return IllegalCharacters::GetInstance()->containsNone(file_name); } -void ReplaceIllegalCharactersInPath(base::FilePath::StringType* file_name, +void ReplaceIllegalCharactersInPath(FilePath::StringType* file_name, char replace_char) { DCHECK(file_name); DCHECK(!(IllegalCharacters::GetInstance()->contains(replace_char))); // Remove leading and trailing whitespace. - base::TrimWhitespace(*file_name, base::TRIM_ALL, file_name); + TrimWhitespace(*file_name, TRIM_ALL, file_name); IllegalCharacters* illegal = IllegalCharacters::GetInstance(); int cursor = 0; // The ICU macros expect an int. @@ -133,8 +132,7 @@ void ReplaceIllegalCharactersInPath(base::FilePath::StringType* file_name, } } -bool LocaleAwareCompareFilenames(const base::FilePath& a, - const base::FilePath& b) { +bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) { 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. @@ -144,31 +142,31 @@ bool LocaleAwareCompareFilenames(const base::FilePath& a, collator->setStrength(icu::Collator::TERTIARY); #if defined(OS_WIN) - return base::i18n::CompareString16WithCollator(collator.get(), - base::WideToUTF16(a.value()), base::WideToUTF16(b.value())) == UCOL_LESS; + return CompareString16WithCollator(collator.get(), + WideToUTF16(a.value()), WideToUTF16(b.value())) == UCOL_LESS; #elif defined(OS_POSIX) // On linux, the file system encoding is not defined. We assume // SysNativeMBToWide takes care of it. - return base::i18n::CompareString16WithCollator( + return CompareString16WithCollator( collator.get(), - base::WideToUTF16(base::SysNativeMBToWide(a.value().c_str())), - base::WideToUTF16(base::SysNativeMBToWide(b.value().c_str())) - ) == UCOL_LESS; + WideToUTF16(SysNativeMBToWide(a.value().c_str())), + WideToUTF16(SysNativeMBToWide(b.value().c_str()))) == UCOL_LESS; #else #error Not implemented on your system #endif } -void NormalizeFileNameEncoding(base::FilePath* file_name) { +void NormalizeFileNameEncoding(FilePath* file_name) { #if defined(OS_CHROMEOS) std::string normalized_str; - if (base::ConvertToUtf8AndNormalize(file_name->BaseName().value(), - base::kCodepageUTF8, - &normalized_str)) { - *file_name = file_name->DirName().Append(base::FilePath(normalized_str)); + if (ConvertToUtf8AndNormalize(file_name->BaseName().value(), + kCodepageUTF8, + &normalized_str)) { + *file_name = file_name->DirName().Append(FilePath(normalized_str)); } #endif } -} // namespace +} // namespace i18n +} // namespace base diff --git a/base/i18n/file_util_icu.h b/base/i18n/file_util_icu.h index 15526c3..7dd94cd 100644 --- a/base/i18n/file_util_icu.h +++ b/base/i18n/file_util_icu.h @@ -11,11 +11,12 @@ #include "base/i18n/base_i18n_export.h" #include "base/strings/string16.h" -namespace file_util { +namespace base { +namespace i18n { // Returns true if file_name does not have any illegal character. The input // param has the same restriction as that for ReplaceIllegalCharacters. -BASE_I18N_EXPORT bool IsFilenameLegal(const base::string16& file_name); +BASE_I18N_EXPORT 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 @@ -25,19 +26,20 @@ BASE_I18N_EXPORT bool IsFilenameLegal(const base::string16& file_name); // file_name == "bad:file*name?.txt", changed to: "bad-file-name-.txt" when // 'replace_char' is '-'. BASE_I18N_EXPORT void ReplaceIllegalCharactersInPath( - base::FilePath::StringType* file_name, + FilePath::StringType* file_name, char 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. -BASE_I18N_EXPORT bool LocaleAwareCompareFilenames(const base::FilePath& a, - const base::FilePath& b); +BASE_I18N_EXPORT bool LocaleAwareCompareFilenames(const FilePath& a, + const FilePath& b); // Calculates the canonical file-system representation of |file_name| base name. // Modifies |file_name| in place. No-op if not on ChromeOS. -BASE_I18N_EXPORT void NormalizeFileNameEncoding(base::FilePath* file_name); +BASE_I18N_EXPORT void NormalizeFileNameEncoding(FilePath* file_name); -} // namespace file_util +} // namespace i18n +} // namespace base #endif // BASE_I18N_FILE_UTIL_ICU_H_ diff --git a/base/i18n/file_util_icu_unittest.cc b/base/i18n/file_util_icu_unittest.cc index dd81226..cdb48a1 100644 --- a/base/i18n/file_util_icu_unittest.cc +++ b/base/i18n/file_util_icu_unittest.cc @@ -9,6 +9,9 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +namespace base { +namespace i18n { + // file_util winds up using autoreleased objects on the Mac, so this needs // to be a PlatformTest class FileUtilICUTest : public PlatformTest { @@ -29,7 +32,7 @@ static const struct goodbad_pair { TEST_F(FileUtilICUTest, ReplaceIllegalCharacersInPathLinuxTest) { for (size_t i = 0; i < arraysize(kIllegalCharacterCases); ++i) { std::string bad_name(kIllegalCharacterCases[i].bad_name); - file_util::ReplaceIllegalCharactersInPath(&bad_name, '-'); + ReplaceIllegalCharactersInPath(&bad_name, '-'); EXPECT_EQ(kIllegalCharacterCases[i].good_name, bad_name); } } @@ -70,12 +73,12 @@ TEST_F(FileUtilICUTest, ReplaceIllegalCharactersInPathTest) { for (size_t i = 0; i < arraysize(kIllegalCharacterCases); ++i) { #if defined(OS_WIN) std::wstring bad_name(kIllegalCharacterCases[i].bad_name); - file_util::ReplaceIllegalCharactersInPath(&bad_name, '-'); + ReplaceIllegalCharactersInPath(&bad_name, '-'); EXPECT_EQ(kIllegalCharacterCases[i].good_name, bad_name); #elif defined(OS_MACOSX) - std::string bad_name(base::WideToUTF8(kIllegalCharacterCases[i].bad_name)); - file_util::ReplaceIllegalCharactersInPath(&bad_name, '-'); - EXPECT_EQ(base::WideToUTF8(kIllegalCharacterCases[i].good_name), bad_name); + std::string bad_name(WideToUTF8(kIllegalCharacterCases[i].bad_name)); + ReplaceIllegalCharactersInPath(&bad_name, '-'); + EXPECT_EQ(WideToUTF8(kIllegalCharacterCases[i].good_name), bad_name); #endif } } @@ -96,12 +99,14 @@ static const struct normalize_name_encoding_test_cases { TEST_F(FileUtilICUTest, NormalizeFileNameEncoding) { for (size_t i = 0; i < arraysize(kNormalizeFileNameEncodingTestCases); i++) { - base::FilePath path(kNormalizeFileNameEncodingTestCases[i].original_path); - file_util::NormalizeFileNameEncoding(&path); - EXPECT_EQ( - base::FilePath(kNormalizeFileNameEncodingTestCases[i].normalized_path), - path); + FilePath path(kNormalizeFileNameEncodingTestCases[i].original_path); + NormalizeFileNameEncoding(&path); + EXPECT_EQ(FilePath(kNormalizeFileNameEncodingTestCases[i].normalized_path), + path); } } #endif + +} // namespace i18n +} // namespace base diff --git a/chrome/browser/download/save_package_file_picker.cc b/chrome/browser/download/save_package_file_picker.cc index 439bad9..f45440c 100644 --- a/chrome/browser/download/save_package_file_picker.cc +++ b/chrome/browser/download/save_package_file_picker.cc @@ -255,7 +255,7 @@ void SavePackageFilePicker::FileSelected( } base::FilePath path_copy(path); - file_util::NormalizeFileNameEncoding(&path_copy); + base::i18n::NormalizeFileNameEncoding(&path_copy); download_prefs_->SetSaveFilePath(path_copy.DirName()); diff --git a/chrome/browser/extensions/api/bookmarks/bookmarks_api.cc b/chrome/browser/extensions/api/bookmarks/bookmarks_api.cc index 8361b94..8dfc29a 100644 --- a/chrome/browser/extensions/api/bookmarks/bookmarks_api.cc +++ b/chrome/browser/extensions/api/bookmarks/bookmarks_api.cc @@ -85,7 +85,7 @@ base::FilePath GetDefaultFilepathForBookmarkExport() { base::TimeFormatShortDateNumeric(time)); #endif - file_util::ReplaceIllegalCharactersInPath(&filename, '_'); + base::i18n::ReplaceIllegalCharactersInPath(&filename, '_'); base::FilePath default_path; PathService::Get(chrome::DIR_USER_DOCUMENTS, &default_path); diff --git a/chrome/browser/shell_integration_linux.cc b/chrome/browser/shell_integration_linux.cc index 24a1c55..47a033e 100644 --- a/chrome/browser/shell_integration_linux.cc +++ b/chrome/browser/shell_integration_linux.cc @@ -695,7 +695,7 @@ base::FilePath GetWebShortcutFilename(const GURL& url) { // Use a prefix, because xdg-desktop-menu requires it. std::string filename = std::string(chrome::kBrowserProcessExecutableName) + "-" + url.spec(); - file_util::ReplaceIllegalCharactersInPath(&filename, '_'); + base::i18n::ReplaceIllegalCharactersInPath(&filename, '_'); base::FilePath desktop_path; if (!PathService::Get(base::DIR_USER_DESKTOP, &desktop_path)) @@ -725,7 +725,7 @@ base::FilePath GetExtensionShortcutFilename(const base::FilePath& profile_path, .append(extension_id) .append("-") .append(profile_path.BaseName().value()); - file_util::ReplaceIllegalCharactersInPath(&filename, '_'); + base::i18n::ReplaceIllegalCharactersInPath(&filename, '_'); // Spaces in filenames break xdg-desktop-menu // (see https://bugs.freedesktop.org/show_bug.cgi?id=66605). base::ReplaceChars(filename, " ", "_", &filename); @@ -741,7 +741,7 @@ std::vector<base::FilePath> GetExistingProfileShortcutFilenames( prefix.append("-"); std::string suffix("-"); suffix.append(profile_path.BaseName().value()); - file_util::ReplaceIllegalCharactersInPath(&suffix, '_'); + base::i18n::ReplaceIllegalCharactersInPath(&suffix, '_'); // Spaces in filenames break xdg-desktop-menu // (see https://bugs.freedesktop.org/show_bug.cgi?id=66605). base::ReplaceChars(suffix, " ", "_", &suffix); diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc index b62d64e..6b4961b 100644 --- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc +++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc @@ -887,7 +887,7 @@ void PrintPreviewHandler::PrintToPdf() { base::UTF16ToUTF8(print_job_title_utf16); #endif - file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); + base::i18n::ReplaceIllegalCharactersInPath(&print_job_title, '_'); base::FilePath default_filename(print_job_title); default_filename = default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc index a675bfba..0da4bce 100644 --- a/chrome/browser/web_applications/web_app.cc +++ b/chrome/browser/web_applications/web_app.cc @@ -141,7 +141,7 @@ base::FilePath GetSanitizedFileName(const base::string16& name) { #else std::string file_name = base::UTF16ToUTF8(name); #endif - file_util::ReplaceIllegalCharactersInPath(&file_name, '_'); + base::i18n::ReplaceIllegalCharactersInPath(&file_name, '_'); return base::FilePath(file_name); } @@ -426,7 +426,7 @@ void GetIconsInfo(const WebApplicationInfo& app_info, #if defined(OS_LINUX) std::string GetWMClassFromAppName(std::string app_name) { - file_util::ReplaceIllegalCharactersInPath(&app_name, '_'); + base::i18n::ReplaceIllegalCharactersInPath(&app_name, '_'); base::TrimString(app_name, "_", &app_name); return app_name; } diff --git a/content/browser/download/save_package.cc b/content/browser/download/save_package.cc index a37035d..b3e5d44 100644 --- a/content/browser/download/save_package.cc +++ b/content/browser/download/save_package.cc @@ -1244,7 +1244,7 @@ base::FilePath SavePackage::GetSuggestedNameForSaveAs( name_with_proper_ext = EnsureHtmlExtension(name_with_proper_ext); base::FilePath::StringType file_name = name_with_proper_ext.value(); - file_util::ReplaceIllegalCharactersInPath(&file_name, ' '); + base::i18n::ReplaceIllegalCharactersInPath(&file_name, ' '); return base::FilePath(file_name); } diff --git a/net/base/directory_lister.cc b/net/base/directory_lister.cc index e75e9f8..2865239 100644 --- a/net/base/directory_lister.cc +++ b/net/base/directory_lister.cc @@ -41,8 +41,8 @@ bool CompareAlphaDirsFirst(const DirectoryLister::DirectoryListerData& a, if (a_is_directory != b_is_directory) return a_is_directory; - return file_util::LocaleAwareCompareFilenames(a.info.GetName(), - b.info.GetName()); + return base::i18n::LocaleAwareCompareFilenames(a.info.GetName(), + b.info.GetName()); } bool CompareDate(const DirectoryLister::DirectoryListerData& a, @@ -66,7 +66,7 @@ bool CompareDate(const DirectoryLister::DirectoryListerData& a, // Static. bool CompareFullPath(const DirectoryLister::DirectoryListerData& a, const DirectoryLister::DirectoryListerData& b) { - return file_util::LocaleAwareCompareFilenames(a.path, b.path); + return base::i18n::LocaleAwareCompareFilenames(a.path, b.path); } void SortData(std::vector<DirectoryLister::DirectoryListerData>* data, diff --git a/net/base/directory_lister_unittest.cc b/net/base/directory_lister_unittest.cc index 005ce0d..88c517d 100644 --- a/net/base/directory_lister_unittest.cc +++ b/net/base/directory_lister_unittest.cc @@ -50,7 +50,7 @@ class ListerDelegate : public DirectoryLister::DirectoryListerDelegate { for (size_t previous = 0, current = 1; current < file_list_.size(); previous++, current++) { - EXPECT_TRUE(file_util::LocaleAwareCompareFilenames( + EXPECT_TRUE(base::i18n::LocaleAwareCompareFilenames( paths_[previous], paths_[current])); } } @@ -71,7 +71,7 @@ class ListerDelegate : public DirectoryLister::DirectoryListerDelegate { file_list_[current].GetName().BaseName().value()); EXPECT_EQ(file_list_[previous].IsDirectory(), file_list_[current].IsDirectory()); - EXPECT_TRUE(file_util::LocaleAwareCompareFilenames( + EXPECT_TRUE(base::i18n::LocaleAwareCompareFilenames( file_list_[previous].GetName(), file_list_[current].GetName())); } diff --git a/net/base/filename_util_icu.cc b/net/base/filename_util_icu.cc index 72bce6e..8c22eec 100644 --- a/net/base/filename_util_icu.cc +++ b/net/base/filename_util_icu.cc @@ -24,7 +24,7 @@ bool IsSafePortablePathComponent(const base::FilePath& component) { return !component.empty() && (component == component.BaseName()) && (component == component.StripTrailingSeparators()) && FilePathToString16(component, &component16) && - file_util::IsFilenameLegal(component16) && + base::i18n::IsFilenameLegal(component16) && !IsShellIntegratedExtension(extension) && (sanitized == component.value()) && !IsReservedName(component.value()); } @@ -56,7 +56,7 @@ base::string16 GetSuggestedFilename(const GURL& url, suggested_name, mime_type, default_name, - base::Bind(&file_util::ReplaceIllegalCharactersInPath)); + base::Bind(&base::i18n::ReplaceIllegalCharactersInPath)); } base::FilePath GenerateFileName(const GURL& url, @@ -72,14 +72,14 @@ base::FilePath GenerateFileName(const GURL& url, suggested_name, mime_type, default_file_name, - base::Bind(&file_util::ReplaceIllegalCharactersInPath))); + base::Bind(&base::i18n::ReplaceIllegalCharactersInPath))); #if defined(OS_CHROMEOS) // When doing file manager operations on ChromeOS, the file paths get // normalized in WebKit layer, so let's ensure downloaded files have // normalized names. Otherwise, we won't be able to handle files with NFD // utf8 encoded characters in name. - file_util::NormalizeFileNameEncoding(&generated_name); + base::i18n::NormalizeFileNameEncoding(&generated_name); #endif DCHECK(!generated_name.empty()); diff --git a/printing/printed_document.cc b/printing/printed_document.cc index 6d2a9a0..8265e75 100644 --- a/printing/printed_document.cc +++ b/printing/printed_document.cc @@ -242,7 +242,7 @@ base::FilePath PrintedDocument::CreateDebugDumpPath( #else // OS_WIN system_filename = base::UTF16ToUTF8(filename); #endif // OS_WIN - file_util::ReplaceIllegalCharactersInPath(&system_filename, '_'); + base::i18n::ReplaceIllegalCharactersInPath(&system_filename, '_'); return g_debug_dump_info.Get().Append(system_filename).AddExtension( extension); } diff --git a/ui/base/dragdrop/os_exchange_data_provider_win.cc b/ui/base/dragdrop/os_exchange_data_provider_win.cc index 1d38f76..b80ac40 100644 --- a/ui/base/dragdrop/os_exchange_data_provider_win.cc +++ b/ui/base/dragdrop/os_exchange_data_provider_win.cc @@ -917,7 +917,7 @@ static void CreateValidFileNameFromTitle(const GURL& url, } } else { *validated = title; - file_util::ReplaceIllegalCharactersInPath(validated, '-'); + base::i18n::ReplaceIllegalCharactersInPath(validated, '-'); } static const wchar_t extension[] = L".url"; static const size_t max_length = MAX_PATH - arraysize(extension); diff --git a/ui/base/l10n/l10n_util.cc b/ui/base/l10n/l10n_util.cc index 1dc036a2..55c4d04 100644 --- a/ui/base/l10n/l10n_util.cc +++ b/ui/base/l10n/l10n_util.cc @@ -225,7 +225,7 @@ bool IsLocalePartiallyPopulated(const std::string& locale_name) { bool IsLocaleAvailable(const std::string& locale) { // If locale has any illegal characters in it, we don't want to try to // load it because it may be pointing outside the locale data file directory. - if (!file_util::IsFilenameLegal(base::ASCIIToUTF16(locale))) + if (!base::i18n::IsFilenameLegal(base::ASCIIToUTF16(locale))) return false; // IsLocalePartiallyPopulated() can be called here for an early return w/o |