diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-05 22:36:56 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-05 22:36:56 +0000 |
commit | 970399b3aaa0a7d76dd1743654d8e1f7aed41cec (patch) | |
tree | a28d79a6023270c5c5c46c9d651e892f5d313fae /base/file_util.cc | |
parent | 749eea04dd5fd17761046e19c177735a8b9fa209 (diff) | |
download | chromium_src-970399b3aaa0a7d76dd1743654d8e1f7aed41cec.zip chromium_src-970399b3aaa0a7d76dd1743654d8e1f7aed41cec.tar.gz chromium_src-970399b3aaa0a7d76dd1743654d8e1f7aed41cec.tar.bz2 |
* switch download manager to using FilePath
* add empty() function to FilePath
* implement file_util::GetFileExtensionFromPath
Review URL: http://codereview.chromium.org/17032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7564 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util.cc')
-rw-r--r-- | base/file_util.cc | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/base/file_util.cc b/base/file_util.cc index fe33c32..e4c3ae7 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); } |