summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-07 23:59:15 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-07 23:59:15 +0000
commit6bc03dea3c8fe7578a19d0a31bfdc123bc3198c6 (patch)
treebab7a1efa04e0bf9945085ce6ca3dab2ef85c51f /base
parentf09c1ddad8c111d0b678ad36393785a30d1ebcf0 (diff)
downloadchromium_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
Diffstat (limited to 'base')
-rw-r--r--base/i18n/file_util_icu.cc36
-rw-r--r--base/i18n/file_util_icu.h16
-rw-r--r--base/i18n/file_util_icu_unittest.cc25
3 files changed, 41 insertions, 36 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