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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) { | 145 bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) { |
146 UErrorCode error_code = U_ZERO_ERROR; | 146 UErrorCode error_code = U_ZERO_ERROR; |
147 // Use the default collator. The default locale should have been properly | 147 // Use the default collator. The default locale should have been properly |
148 // set by the time this constructor is called. | 148 // set by the time this constructor is called. |
149 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(error_code)); | 149 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(error_code)); |
150 DCHECK(U_SUCCESS(error_code)); | 150 DCHECK(U_SUCCESS(error_code)); |
151 // Make it case-sensitive. | 151 // Make it case-sensitive. |
152 collator->setStrength(icu::Collator::TERTIARY); | 152 collator->setStrength(icu::Collator::TERTIARY); |
153 | 153 |
154 #if defined(OS_WIN) | 154 #if defined(OS_WIN) |
155 return CompareString16WithCollator(collator.get(), | 155 return CompareString16WithCollator(*collator, WideToUTF16(a.value()), |
156 WideToUTF16(a.value()), WideToUTF16(b.value())) == UCOL_LESS; | 156 WideToUTF16(b.value())) == UCOL_LESS; |
157 | 157 |
158 #elif defined(OS_POSIX) | 158 #elif defined(OS_POSIX) |
159 // On linux, the file system encoding is not defined. We assume | 159 // On linux, the file system encoding is not defined. We assume |
160 // SysNativeMBToWide takes care of it. | 160 // SysNativeMBToWide takes care of it. |
161 return CompareString16WithCollator( | 161 return CompareString16WithCollator( |
162 collator.get(), | 162 *collator, WideToUTF16(SysNativeMBToWide(a.value().c_str())), |
163 WideToUTF16(SysNativeMBToWide(a.value().c_str())), | 163 WideToUTF16(SysNativeMBToWide(b.value().c_str()))) == UCOL_LESS; |
164 WideToUTF16(SysNativeMBToWide(b.value().c_str()))) == UCOL_LESS; | |
165 #else | 164 #else |
166 #error Not implemented on your system | 165 #error Not implemented on your system |
167 #endif | 166 #endif |
168 } | 167 } |
169 | 168 |
170 void NormalizeFileNameEncoding(FilePath* file_name) { | 169 void NormalizeFileNameEncoding(FilePath* file_name) { |
171 #if defined(OS_CHROMEOS) | 170 #if defined(OS_CHROMEOS) |
172 std::string normalized_str; | 171 std::string normalized_str; |
173 if (ConvertToUtf8AndNormalize(file_name->BaseName().value(), | 172 if (ConvertToUtf8AndNormalize(file_name->BaseName().value(), |
174 kCodepageUTF8, | 173 kCodepageUTF8, |
175 &normalized_str)) { | 174 &normalized_str)) { |
176 *file_name = file_name->DirName().Append(FilePath(normalized_str)); | 175 *file_name = file_name->DirName().Append(FilePath(normalized_str)); |
177 } | 176 } |
178 #endif | 177 #endif |
179 } | 178 } |
180 | 179 |
181 } // namespace i18n | 180 } // namespace i18n |
182 } // namespace base | 181 } // namespace base |
OLD | NEW |