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

Unified Diff: base/file_path.cc

Issue 10872072: foo (1).user.js, not foo.user (1).js. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: grump Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/file_path_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_path.cc
diff --git a/base/file_path.cc b/base/file_path.cc
index b9308989a05ddbaf3c714e419e3253b3e8673d3c..98cbfde9d6daa26386f146a9389fda8126022397 100644
--- a/base/file_path.cc
+++ b/base/file_path.cc
@@ -44,7 +44,8 @@ typedef FilePath::StringType StringType;
namespace {
-const char* kCommonDoubleExtensions[] = { "gz", "z", "bz2" };
+const char* kCommonDoubleExtensionSuffixes[] = { "gz", "z", "bz2" };
+const char* kCommonDoubleExtensions[] = { "user.js" };
// If this FilePath contains a drive letter specification, returns the
// position of the last character of the drive letter specification,
@@ -130,30 +131,32 @@ StringType::size_type ExtensionSeparatorPosition(const StringType& path) {
if (last_dot == StringType::npos || last_dot == 0U)
return last_dot;
- // Special case .<extension1>.<extension2>, but only if the final extension
- // is one of a few common double extensions.
- StringType extension(path, last_dot + 1);
- bool is_common_double_extension = false;
- for (size_t i = 0; i < arraysize(kCommonDoubleExtensions); ++i) {
- if (LowerCaseEqualsASCII(extension, kCommonDoubleExtensions[i]))
- is_common_double_extension = true;
- }
- if (!is_common_double_extension)
- return last_dot;
-
- // Check that <extension1> is 1-4 characters, otherwise fall back to
- // <extension2>.
const StringType::size_type penultimate_dot =
path.rfind(FilePath::kExtensionSeparator, last_dot - 1);
const StringType::size_type last_separator =
path.find_last_of(FilePath::kSeparators, last_dot - 1,
arraysize(FilePath::kSeparators) - 1);
- if (penultimate_dot != StringType::npos &&
- (last_separator == StringType::npos ||
- penultimate_dot > last_separator) &&
- last_dot - penultimate_dot <= 5U &&
- last_dot - penultimate_dot > 1U) {
- return penultimate_dot;
+
+ if (penultimate_dot == StringType::npos ||
+ (last_separator != StringType::npos &&
+ penultimate_dot < last_separator)) {
+ return last_dot;
+ }
+
+ for (size_t i = 0; i < arraysize(kCommonDoubleExtensions); ++i) {
+ StringType extension(path, penultimate_dot + 1);
+ if (LowerCaseEqualsASCII(extension, kCommonDoubleExtensions[i]))
+ return penultimate_dot;
+ }
+
+ StringType extension(path, last_dot + 1);
+ for (size_t i = 0; i < arraysize(kCommonDoubleExtensionSuffixes); ++i) {
+ if (LowerCaseEqualsASCII(extension, kCommonDoubleExtensionSuffixes[i])) {
+ if ((last_dot - penultimate_dot) <= 5U &&
+ (last_dot - penultimate_dot) > 1U) {
+ return penultimate_dot;
+ }
+ }
}
return last_dot;
« no previous file with comments | « no previous file | base/file_path_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698