diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-06 23:31:41 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-06 23:31:41 +0000 |
commit | 7ae7c2cbd38f886f4056fa7434a6c1189d98ffd2 (patch) | |
tree | e606471e20eb79fea7a05c9005869065bf865ca1 /base | |
parent | cab465ccf2a93d84e0f16987d8754ac2673eb118 (diff) | |
download | chromium_src-7ae7c2cbd38f886f4056fa7434a6c1189d98ffd2.zip chromium_src-7ae7c2cbd38f886f4056fa7434a6c1189d98ffd2.tar.gz chromium_src-7ae7c2cbd38f886f4056fa7434a6c1189d98ffd2.tar.bz2 |
Convert download manager to FilePath.
(Fixed up version of issue 17032. Now passes all unit tests.)
Review URL: http://codereview.chromium.org/16533
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7630 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/file_path.h | 2 | ||||
-rw-r--r-- | base/file_util.cc | 22 | ||||
-rw-r--r-- | base/file_util.h | 6 | ||||
-rw-r--r-- | base/file_util_win.cc | 9 |
4 files changed, 26 insertions, 13 deletions
diff --git a/base/file_path.h b/base/file_path.h index 7beb40e..6ed9320 100644 --- a/base/file_path.h +++ b/base/file_path.h @@ -129,6 +129,8 @@ class FilePath { const StringType& value() const { return path_; } + bool empty() const { return path_.empty(); } + // Returns true if |character| is in kSeparators. static bool IsSeparator(CharType character); diff --git a/base/file_util.cc b/base/file_util.cc index fe33c32..fe7b694 100644 --- a/base/file_util.cc +++ b/base/file_util.cc @@ -79,12 +79,13 @@ void TrimTrailingSeparator(std::wstring* dir) { dir->resize(dir->length() - 1); } -std::wstring GetFileExtensionFromPath(const std::wstring& path) { - std::wstring file_name = GetFilenameFromPath(path); - std::wstring::size_type last_dot = file_name.rfind(L'.'); - return std::wstring(last_dot == std::wstring::npos ? - L"" : - file_name, last_dot+1); +FilePath::StringType GetFileExtensionFromPath(const FilePath& path) { + FilePath::StringType file_name = path.BaseName().value(); + const FilePath::StringType::size_type last_dot = + file_name.rfind(kExtensionSeparator); + return FilePath::StringType(last_dot == FilePath::StringType::npos ? + FILE_PATH_LITERAL("") : + file_name, last_dot+1); } std::wstring GetFilenameWithoutExtensionFromPath(const std::wstring& path) { @@ -374,6 +375,15 @@ bool GetCurrentDirectory(std::wstring* path_str) { *path_str = path.ToWStringHack(); return true; } +std::wstring GetFileExtensionFromPath(const std::wstring& path) { + FilePath::StringType extension = + GetFileExtensionFromPath(FilePath::FromWStringHack(path)); +#if defined(OS_WIN) + return extension; +#elif defined(OS_POSIX) + return UTF8ToWide(extension); +#endif +} bool GetFileInfo(const std::wstring& file_path, FileInfo* results) { return GetFileInfo(FilePath::FromWStringHack(file_path), results); } diff --git a/base/file_util.h b/base/file_util.h index 67cd59f..784ea36 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -77,6 +77,8 @@ std::wstring GetFilenameFromPath(const std::wstring& path); // Returns "jpg" for path "C:\pics\jojo.jpg", or an empty string if // the file has no extension. +FilePath::StringType GetFileExtensionFromPath(const FilePath& path); +// Deprecated temporary compatibility function. std::wstring GetFileExtensionFromPath(const std::wstring& path); // Returns 'jojo' for path "C:\pics\jojo.jpg". @@ -464,8 +466,8 @@ class MemoryMappedFile { // Renames a file using the SHFileOperation API to ensure that the target file // gets the correct default security descriptor in the new path. bool RenameFileAndResetSecurityDescriptor( - const std::wstring& source_file_path, - const std::wstring& target_file_path); + const FilePath& source_file_path, + const FilePath& target_file_path); } // namespace file_util diff --git a/base/file_util_win.cc b/base/file_util_win.cc index c2dbf0a..b50ab09 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -549,12 +549,11 @@ int WriteFile(const std::wstring& filename, const char* data, int size) { return -1; } -bool RenameFileAndResetSecurityDescriptor( - const std::wstring& source_file_path, - const std::wstring& target_file_path) { +bool RenameFileAndResetSecurityDescriptor(const FilePath& source_file_path, + const FilePath& target_file_path) { // The parameters to SHFileOperation must be terminated with 2 NULL chars. - std::wstring source = source_file_path; - std::wstring target = target_file_path; + std::wstring source = source_file_path.value(); + std::wstring target = target_file_path.value(); source.append(1, L'\0'); target.append(1, L'\0'); |