| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // File utilities that use the ICU library go in this file. | 5 // File utilities that use the ICU library go in this file. |
| 6 | 6 |
| 7 #include "base/i18n/file_util_icu.h" | 7 #include "base/i18n/file_util_icu.h" |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/i18n/icu_string_conversions.h" | 10 #include "base/i18n/icu_string_conversions.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 UErrorCode error_code = U_ZERO_ERROR; | 138 UErrorCode error_code = U_ZERO_ERROR; |
| 139 // Use the default collator. The default locale should have been properly | 139 // Use the default collator. The default locale should have been properly |
| 140 // set by the time this constructor is called. | 140 // set by the time this constructor is called. |
| 141 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(error_code)); | 141 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(error_code)); |
| 142 DCHECK(U_SUCCESS(error_code)); | 142 DCHECK(U_SUCCESS(error_code)); |
| 143 // Make it case-sensitive. | 143 // Make it case-sensitive. |
| 144 collator->setStrength(icu::Collator::TERTIARY); | 144 collator->setStrength(icu::Collator::TERTIARY); |
| 145 | 145 |
| 146 #if defined(OS_WIN) | 146 #if defined(OS_WIN) |
| 147 return base::i18n::CompareString16WithCollator(collator.get(), | 147 return base::i18n::CompareString16WithCollator(collator.get(), |
| 148 WideToUTF16(a.value()), WideToUTF16(b.value())) == UCOL_LESS; | 148 base::WideToUTF16(a.value()), base::WideToUTF16(b.value())) == UCOL_LESS; |
| 149 | 149 |
| 150 #elif defined(OS_POSIX) | 150 #elif defined(OS_POSIX) |
| 151 // On linux, the file system encoding is not defined. We assume | 151 // On linux, the file system encoding is not defined. We assume |
| 152 // SysNativeMBToWide takes care of it. | 152 // SysNativeMBToWide takes care of it. |
| 153 return base::i18n::CompareString16WithCollator(collator.get(), | 153 return base::i18n::CompareString16WithCollator( |
| 154 WideToUTF16(base::SysNativeMBToWide(a.value().c_str())), | 154 collator.get(), |
| 155 WideToUTF16(base::SysNativeMBToWide(b.value().c_str()))) == UCOL_LESS; | 155 base::WideToUTF16(base::SysNativeMBToWide(a.value().c_str())), |
| 156 base::WideToUTF16(base::SysNativeMBToWide(b.value().c_str())) |
| 157 ) == UCOL_LESS; |
| 156 #else | 158 #else |
| 157 #error Not implemented on your system | 159 #error Not implemented on your system |
| 158 #endif | 160 #endif |
| 159 } | 161 } |
| 160 | 162 |
| 161 void NormalizeFileNameEncoding(base::FilePath* file_name) { | 163 void NormalizeFileNameEncoding(base::FilePath* file_name) { |
| 162 #if defined(OS_CHROMEOS) | 164 #if defined(OS_CHROMEOS) |
| 163 std::string normalized_str; | 165 std::string normalized_str; |
| 164 if (base::ConvertToUtf8AndNormalize(file_name->BaseName().value(), | 166 if (base::ConvertToUtf8AndNormalize(file_name->BaseName().value(), |
| 165 base::kCodepageUTF8, | 167 base::kCodepageUTF8, |
| 166 &normalized_str)) { | 168 &normalized_str)) { |
| 167 *file_name = file_name->DirName().Append(base::FilePath(normalized_str)); | 169 *file_name = file_name->DirName().Append(base::FilePath(normalized_str)); |
| 168 } | 170 } |
| 169 #endif | 171 #endif |
| 170 } | 172 } |
| 171 | 173 |
| 172 } // namespace | 174 } // namespace |
| OLD | NEW |