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

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

Issue 12286020: Replace FilePath with base::FilePath. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « base/file_util_unittest.cc ('k') | base/path_service_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/file_path.h" 9 #include "base/file_path.h"
10 #include "base/i18n/icu_string_conversions.h" 10 #include "base/i18n/icu_string_conversions.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 }; 130 };
131 131
132 } // namespace 132 } // namespace
133 133
134 namespace file_util { 134 namespace file_util {
135 135
136 bool IsFilenameLegal(const string16& file_name) { 136 bool IsFilenameLegal(const string16& file_name) {
137 return IllegalCharacters::GetInstance()->containsNone(file_name); 137 return IllegalCharacters::GetInstance()->containsNone(file_name);
138 } 138 }
139 139
140 void ReplaceIllegalCharactersInPath(FilePath::StringType* file_name, 140 void ReplaceIllegalCharactersInPath(base::FilePath::StringType* file_name,
141 char replace_char) { 141 char replace_char) {
142 DCHECK(file_name); 142 DCHECK(file_name);
143 143
144 DCHECK(!(IllegalCharacters::GetInstance()->contains(replace_char))); 144 DCHECK(!(IllegalCharacters::GetInstance()->contains(replace_char)));
145 145
146 // Remove leading and trailing whitespace. 146 // Remove leading and trailing whitespace.
147 TrimWhitespace(*file_name, TRIM_ALL, file_name); 147 TrimWhitespace(*file_name, TRIM_ALL, file_name);
148 148
149 IllegalCharacters* illegal = IllegalCharacters::GetInstance(); 149 IllegalCharacters* illegal = IllegalCharacters::GetInstance();
150 int cursor = 0; // The ICU macros expect an int. 150 int cursor = 0; // The ICU macros expect an int.
(...skipping 22 matching lines...) Expand all
173 if (illegal->contains(code_point)) { 173 if (illegal->contains(code_point)) {
174 file_name->replace(char_begin, cursor - char_begin, 1, replace_char); 174 file_name->replace(char_begin, cursor - char_begin, 1, replace_char);
175 // We just made the potentially multi-byte/word char into one that only 175 // We just made the potentially multi-byte/word char into one that only
176 // takes one byte/word, so need to adjust the cursor to point to the next 176 // takes one byte/word, so need to adjust the cursor to point to the next
177 // character again. 177 // character again.
178 cursor = char_begin + 1; 178 cursor = char_begin + 1;
179 } 179 }
180 } 180 }
181 } 181 }
182 182
183 bool LocaleAwareCompareFilenames(const FilePath& a, const FilePath& b) { 183 bool LocaleAwareCompareFilenames(const base::FilePath& a,
184 const base::FilePath& b) {
184 #if defined(OS_WIN) 185 #if defined(OS_WIN)
185 return LocaleAwareComparator::GetInstance()->Compare(a.value().c_str(), 186 return LocaleAwareComparator::GetInstance()->Compare(a.value().c_str(),
186 b.value().c_str()) < 0; 187 b.value().c_str()) < 0;
187 188
188 #elif defined(OS_POSIX) 189 #elif defined(OS_POSIX)
189 // On linux, the file system encoding is not defined. We assume 190 // On linux, the file system encoding is not defined. We assume
190 // SysNativeMBToWide takes care of it. 191 // SysNativeMBToWide takes care of it.
191 // 192 //
192 // ICU's collator can take strings in OS native encoding. But we convert the 193 // ICU's collator can take strings in OS native encoding. But we convert the
193 // strings to UTF-16 ourselves to ensure conversion consistency. 194 // strings to UTF-16 ourselves to ensure conversion consistency.
194 // TODO(yuzo): Perhaps we should define SysNativeMBToUTF16? 195 // TODO(yuzo): Perhaps we should define SysNativeMBToUTF16?
195 return LocaleAwareComparator::GetInstance()->Compare( 196 return LocaleAwareComparator::GetInstance()->Compare(
196 WideToUTF16(base::SysNativeMBToWide(a.value().c_str())), 197 WideToUTF16(base::SysNativeMBToWide(a.value().c_str())),
197 WideToUTF16(base::SysNativeMBToWide(b.value().c_str()))) < 0; 198 WideToUTF16(base::SysNativeMBToWide(b.value().c_str()))) < 0;
198 #else 199 #else
199 #error Not implemented on your system 200 #error Not implemented on your system
200 #endif 201 #endif
201 } 202 }
202 203
203 void NormalizeFileNameEncoding(FilePath* file_name) { 204 void NormalizeFileNameEncoding(base::FilePath* file_name) {
204 #if defined(OS_CHROMEOS) 205 #if defined(OS_CHROMEOS)
205 std::string normalized_str; 206 std::string normalized_str;
206 if (base::ConvertToUtf8AndNormalize(file_name->BaseName().value(), 207 if (base::ConvertToUtf8AndNormalize(file_name->BaseName().value(),
207 base::kCodepageUTF8, 208 base::kCodepageUTF8,
208 &normalized_str)) { 209 &normalized_str)) {
209 *file_name = file_name->DirName().Append(FilePath(normalized_str)); 210 *file_name = file_name->DirName().Append(base::FilePath(normalized_str));
210 } 211 }
211 #endif 212 #endif
212 } 213 }
213 214
214 } // namespace 215 } // namespace
OLDNEW
« no previous file with comments | « base/file_util_unittest.cc ('k') | base/path_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698