diff options
Diffstat (limited to 'base/file_util.cc')
-rw-r--r-- | base/file_util.cc | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/base/file_util.cc b/base/file_util.cc index e4c3ae7..f0d66b5 100644 --- a/base/file_util.cc +++ b/base/file_util.cc @@ -79,13 +79,12 @@ void TrimTrailingSeparator(std::wstring* dir) { dir->resize(dir->length() - 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 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); } std::wstring GetFilenameWithoutExtensionFromPath(const std::wstring& path) { @@ -375,15 +374,6 @@ 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); } @@ -391,7 +381,11 @@ std::wstring GetFilenameFromPath(const std::wstring& path) { if (path.empty() || EndsWithSeparator(path)) return std::wstring(); - return FilePath::FromWStringHack(path).BaseName().ToWStringHack(); +#if defined(OS_WIN) + return FilePath::FromWStringHack(path).BaseName(); +#elif defined(OS_POSIX) + return UTF8ToWide(FilePath::FromWStringHack(path).BaseName()); +#endif } bool GetFileSize(const std::wstring& file_path, int64* file_size) { return GetFileSize(FilePath::FromWStringHack(file_path), file_size); |