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

Side by Side Diff: base/file_path.cc

Issue 147017: Allow extension extensions to be case-insensitive. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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_path.h ('k') | base/file_path_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) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 #include "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 7
8 // These includes are just for the *Hack functions, and should be removed 8 // These includes are just for the *Hack functions, and should be removed
9 // when those functions are removed. 9 // when those functions are removed.
10 #include "base/string_piece.h" 10 #include "base/string_piece.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 if (extension.empty() || extension == StringType(1, kExtensionSeparator)) 277 if (extension.empty() || extension == StringType(1, kExtensionSeparator))
278 return no_ext; 278 return no_ext;
279 279
280 StringType str = no_ext.value(); 280 StringType str = no_ext.value();
281 if (extension[0] != kExtensionSeparator) 281 if (extension[0] != kExtensionSeparator)
282 str.append(1, kExtensionSeparator); 282 str.append(1, kExtensionSeparator);
283 str.append(extension); 283 str.append(extension);
284 return FilePath(str); 284 return FilePath(str);
285 } 285 }
286 286
287 bool FilePath::MatchesExtension(const StringType& extension) const {
288 FilePath::StringType current_extension = Extension();
289
290 if (current_extension.length() != extension.length())
291 return false;
292
293 return std::equal(extension.begin(),
294 extension.end(),
295 current_extension.begin(),
296 CaseInsensitiveCompare<FilePath::CharType>());
297 }
298
287 FilePath FilePath::Append(const StringType& component) const { 299 FilePath FilePath::Append(const StringType& component) const {
288 DCHECK(!IsPathAbsolute(component)); 300 DCHECK(!IsPathAbsolute(component));
289 if (path_.compare(kCurrentDirectory) == 0) { 301 if (path_.compare(kCurrentDirectory) == 0) {
290 // Append normally doesn't do any normalization, but as a special case, 302 // Append normally doesn't do any normalization, but as a special case,
291 // when appending to kCurrentDirectory, just return a new path for the 303 // when appending to kCurrentDirectory, just return a new path for the
292 // component argument. Appending component to kCurrentDirectory would 304 // component argument. Appending component to kCurrentDirectory would
293 // serve no purpose other than needlessly lengthening the path, and 305 // serve no purpose other than needlessly lengthening the path, and
294 // it's likely in practice to wind up with FilePath objects containing 306 // it's likely in practice to wind up with FilePath objects containing
295 // only kCurrentDirectory when calling DirName on a single relative path 307 // only kCurrentDirectory when calling DirName on a single relative path
296 // component. 308 // component.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 --pos) { 393 --pos) {
382 // If the string only has two separators and they're at the beginning, 394 // If the string only has two separators and they're at the beginning,
383 // don't strip them, unless the string began with more than two separators. 395 // don't strip them, unless the string began with more than two separators.
384 if (pos != start + 1 || last_stripped == start + 2 || 396 if (pos != start + 1 || last_stripped == start + 2 ||
385 !IsSeparator(path_[start - 1])) { 397 !IsSeparator(path_[start - 1])) {
386 path_.resize(pos - 1); 398 path_.resize(pos - 1);
387 last_stripped = pos; 399 last_stripped = pos;
388 } 400 }
389 } 401 }
390 } 402 }
OLDNEW
« no previous file with comments | « base/file_path.h ('k') | base/file_path_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698