Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: base/i18n/file_util_icu.cc

Issue 1446363003: Deleted OS_WIN and all Windows specific files from base. (Closed) Base URL: https://github.com/domokit/mojo.git@base_tests
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/i18n/char_iterator.h ('k') | base/i18n/file_util_icu_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 DCHECK(!(illegal->DisallowedLeadingOrTrailing(replace_char))); 108 DCHECK(!(illegal->DisallowedLeadingOrTrailing(replace_char)));
109 109
110 int cursor = 0; // The ICU macros expect an int. 110 int cursor = 0; // The ICU macros expect an int.
111 while (cursor < static_cast<int>(file_name->size())) { 111 while (cursor < static_cast<int>(file_name->size())) {
112 int char_begin = cursor; 112 int char_begin = cursor;
113 uint32 code_point; 113 uint32 code_point;
114 #if defined(OS_MACOSX) 114 #if defined(OS_MACOSX)
115 // Mac uses UTF-8 encoding for filenames. 115 // Mac uses UTF-8 encoding for filenames.
116 U8_NEXT(file_name->data(), cursor, static_cast<int>(file_name->length()), 116 U8_NEXT(file_name->data(), cursor, static_cast<int>(file_name->length()),
117 code_point); 117 code_point);
118 #elif defined(OS_WIN)
119 // Windows uses UTF-16 encoding for filenames.
120 U16_NEXT(file_name->data(), cursor, static_cast<int>(file_name->length()),
121 code_point);
122 #elif defined(OS_POSIX) 118 #elif defined(OS_POSIX)
123 // Linux doesn't actually define an encoding. It basically allows anything 119 // Linux doesn't actually define an encoding. It basically allows anything
124 // except for a few special ASCII characters. 120 // except for a few special ASCII characters.
125 unsigned char cur_char = static_cast<unsigned char>((*file_name)[cursor++]); 121 unsigned char cur_char = static_cast<unsigned char>((*file_name)[cursor++]);
126 if (cur_char >= 0x80) 122 if (cur_char >= 0x80)
127 continue; 123 continue;
128 code_point = cur_char; 124 code_point = cur_char;
129 #else 125 #else
130 NOTREACHED(); 126 NOTREACHED();
131 #endif 127 #endif
(...skipping 12 matching lines...) Expand all
144 140
145 bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) { 141 bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) {
146 UErrorCode error_code = U_ZERO_ERROR; 142 UErrorCode error_code = U_ZERO_ERROR;
147 // Use the default collator. The default locale should have been properly 143 // Use the default collator. The default locale should have been properly
148 // set by the time this constructor is called. 144 // set by the time this constructor is called.
149 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(error_code)); 145 scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(error_code));
150 DCHECK(U_SUCCESS(error_code)); 146 DCHECK(U_SUCCESS(error_code));
151 // Make it case-sensitive. 147 // Make it case-sensitive.
152 collator->setStrength(icu::Collator::TERTIARY); 148 collator->setStrength(icu::Collator::TERTIARY);
153 149
154 #if defined(OS_WIN) 150 #if defined(OS_POSIX)
155 return CompareString16WithCollator(*collator, WideToUTF16(a.value()),
156 WideToUTF16(b.value())) == UCOL_LESS;
157
158 #elif defined(OS_POSIX)
159 // On linux, the file system encoding is not defined. We assume 151 // On linux, the file system encoding is not defined. We assume
160 // SysNativeMBToWide takes care of it. 152 // SysNativeMBToWide takes care of it.
161 return CompareString16WithCollator( 153 return CompareString16WithCollator(
162 *collator, WideToUTF16(SysNativeMBToWide(a.value().c_str())), 154 *collator, WideToUTF16(SysNativeMBToWide(a.value().c_str())),
163 WideToUTF16(SysNativeMBToWide(b.value().c_str()))) == UCOL_LESS; 155 WideToUTF16(SysNativeMBToWide(b.value().c_str()))) == UCOL_LESS;
164 #else 156 #else
165 #error Not implemented on your system 157 #error Not implemented on your system
166 #endif 158 #endif
167 } 159 }
168 160
169 void NormalizeFileNameEncoding(FilePath* file_name) { 161 void NormalizeFileNameEncoding(FilePath* file_name) {
170 #if defined(OS_CHROMEOS) 162 #if defined(OS_CHROMEOS)
171 std::string normalized_str; 163 std::string normalized_str;
172 if (ConvertToUtf8AndNormalize(file_name->BaseName().value(), 164 if (ConvertToUtf8AndNormalize(file_name->BaseName().value(),
173 kCodepageUTF8, 165 kCodepageUTF8,
174 &normalized_str)) { 166 &normalized_str)) {
175 *file_name = file_name->DirName().Append(FilePath(normalized_str)); 167 *file_name = file_name->DirName().Append(FilePath(normalized_str));
176 } 168 }
177 #endif 169 #endif
178 } 170 }
179 171
180 } // namespace i18n 172 } // namespace i18n
181 } // namespace base 173 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/char_iterator.h ('k') | base/i18n/file_util_icu_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698