diff options
author | rolandsteiner@chromium.org <rolandsteiner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-28 05:40:09 +0000 |
---|---|---|
committer | rolandsteiner@chromium.org <rolandsteiner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-28 05:40:09 +0000 |
commit | eccb9d1b07fb140a04ba58b6840f26be99810a94 (patch) | |
tree | dfcd4494b49fb7d0fdfd4c04bcda9d943a979439 /base/file_path.h | |
parent | 403c62a8e7de84adb39f8a97c6de709067508843 (diff) | |
download | chromium_src-eccb9d1b07fb140a04ba58b6840f26be99810a94.zip chromium_src-eccb9d1b07fb140a04ba58b6840f26be99810a94.tar.gz chromium_src-eccb9d1b07fb140a04ba58b6840f26be99810a94.tar.bz2 |
Fix for bug 10876 that resulted in some refactoring:
The bug originates from extensions being treated case sensitive on Windows and Mac OSX, where they shouldn't be.
Therefore I added generic static methods to FilePath to compare strings in the same way the file system does, and changed the relevant parts of the code to make use of them.
I tested the methods under Windows and Mac OS X. I also wrote a basic version for Linux/Posix that behaves the same way as the original code, so there should at least be no regression.
Also, while fixing this I found some confusion in the code about whether extensions are used with or without leading dot. For this reason I changed some functions that were taking an extension as parameter to instead take the whole file path. This makes calling these functions easier and the caller doesn't need to know whether the extension is supposed to be with or without dot.
In the same vein, I split DownloadManager::IsExecutable into IsExecutableFile, where one again passes in the whole file and doesn't have to worry about getting the extension right, and IsExecutableExtension, which corresponds to the original functionality. Ideally only the former method should be public, but that again would have required further code scrubbing that was (even more) outside of the original bug fix.
Finally, fixed a wrong comment in the file path tests.
BUG=10876
TEST=FilePathTest.MatchesExtension, .CompareIgnoreCase
Review URL: http://codereview.chromium.org/149796
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30323 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_path.h')
-rw-r--r-- | base/file_path.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/base/file_path.h b/base/file_path.h index 5c8f183..7900922 100644 --- a/base/file_path.h +++ b/base/file_path.h @@ -294,6 +294,41 @@ class FilePath { // TODO(port): remove these functions. static FilePath FromWStringHack(const std::wstring& wstring); + // Compare two strings in the same way the file system does. + // Note that these always ignore case, even on file systems that are case- + // sensitive. If case-sensitive comparison is ever needed, add corresponding + // methods here. + // The methods are written as a static method so that they can also be used + // on parts of a file path, e.g., just the extension. + // CompareIgnoreCase() returns -1, 0 or 1 for less-than, equal-to and + // greater-than respectively. + static int CompareIgnoreCase(const StringType& string1, + const StringType& string2); + static bool CompareEqualIgnoreCase(const StringType& string1, + const StringType& string2) { + return CompareIgnoreCase(string1, string2) == 0; + } + static bool CompareLessIgnoreCase(const StringType& string1, + const StringType& string2) { + return CompareIgnoreCase(string1, string2) < 0; + } + +#if defined(OS_MACOSX) + // Returns the string in the special canonical decomposed form as defined for + // HFS, which is close to, but not quite, decomposition form D. See + // http://developer.apple.com/mac/library/technotes/tn/tn1150.html#UnicodeSubtleties + // for further comments. + // Returns the epmty string if the conversion failed. + static StringType GetHFSDecomposedForm(const FilePath::StringType& string); + + // Special UTF-8 version of FastUnicodeCompare. Cf: + // http://developer.apple.com/mac/library/technotes/tn/tn1150.html#StringComparisonAlgorithm + // IMPORTANT: The input strings must be in the special HFS decomposed form! + // (cf. above GetHFSDecomposedForm method) + static int HFSFastUnicodeCompare(const StringType& string1, + const StringType& string2); +#endif + // Older Chromium code assumes that paths are always wstrings. // This function produces a wstring from a FilePath, and is useful to smooth // porting that old code to the FilePath API. |