OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <fstream> | 9 #include <fstream> |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 path_str.append(&FilePath::kSeparators[0], 1); | 72 path_str.append(&FilePath::kSeparators[0], 1); |
73 | 73 |
74 return true; | 74 return true; |
75 } | 75 } |
76 | 76 |
77 void TrimTrailingSeparator(std::wstring* dir) { | 77 void TrimTrailingSeparator(std::wstring* dir) { |
78 while (dir->length() > 1 && EndsWithSeparator(dir)) | 78 while (dir->length() > 1 && EndsWithSeparator(dir)) |
79 dir->resize(dir->length() - 1); | 79 dir->resize(dir->length() - 1); |
80 } | 80 } |
81 | 81 |
82 std::wstring GetFileExtensionFromPath(const std::wstring& path) { | 82 FilePath::StringType GetFileExtensionFromPath(const FilePath& path) { |
83 std::wstring file_name = GetFilenameFromPath(path); | 83 FilePath::StringType file_name = path.BaseName().value(); |
84 std::wstring::size_type last_dot = file_name.rfind(L'.'); | 84 const FilePath::StringType::size_type last_dot = |
85 return std::wstring(last_dot == std::wstring::npos ? | 85 file_name.rfind(kExtensionSeparator); |
86 L"" : | 86 return FilePath::StringType(last_dot == FilePath::StringType::npos ? |
87 file_name, last_dot+1); | 87 FILE_PATH_LITERAL("") : |
| 88 file_name, last_dot+1); |
88 } | 89 } |
89 | 90 |
90 std::wstring GetFilenameWithoutExtensionFromPath(const std::wstring& path) { | 91 std::wstring GetFilenameWithoutExtensionFromPath(const std::wstring& path) { |
91 std::wstring file_name = GetFilenameFromPath(path); | 92 std::wstring file_name = GetFilenameFromPath(path); |
92 std::wstring::size_type last_dot = file_name.rfind(L'.'); | 93 std::wstring::size_type last_dot = file_name.rfind(L'.'); |
93 return file_name.substr(0, last_dot); | 94 return file_name.substr(0, last_dot); |
94 } | 95 } |
95 | 96 |
96 void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix) { | 97 void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix) { |
97 FilePath::StringType& value = | 98 FilePath::StringType& value = |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 bool EndsWithSeparator(const std::wstring& path) { | 368 bool EndsWithSeparator(const std::wstring& path) { |
368 return EndsWithSeparator(FilePath::FromWStringHack(path)); | 369 return EndsWithSeparator(FilePath::FromWStringHack(path)); |
369 } | 370 } |
370 bool GetCurrentDirectory(std::wstring* path_str) { | 371 bool GetCurrentDirectory(std::wstring* path_str) { |
371 FilePath path; | 372 FilePath path; |
372 if (!GetCurrentDirectory(&path)) | 373 if (!GetCurrentDirectory(&path)) |
373 return false; | 374 return false; |
374 *path_str = path.ToWStringHack(); | 375 *path_str = path.ToWStringHack(); |
375 return true; | 376 return true; |
376 } | 377 } |
| 378 std::wstring GetFileExtensionFromPath(const std::wstring& path) { |
| 379 FilePath::StringType extension = |
| 380 GetFileExtensionFromPath(FilePath::FromWStringHack(path)); |
| 381 #if defined(OS_WIN) |
| 382 return extension; |
| 383 #elif defined(OS_POSIX) |
| 384 return UTF8ToWide(extension); |
| 385 #endif |
| 386 } |
377 bool GetFileInfo(const std::wstring& file_path, FileInfo* results) { | 387 bool GetFileInfo(const std::wstring& file_path, FileInfo* results) { |
378 return GetFileInfo(FilePath::FromWStringHack(file_path), results); | 388 return GetFileInfo(FilePath::FromWStringHack(file_path), results); |
379 } | 389 } |
380 std::wstring GetFilenameFromPath(const std::wstring& path) { | 390 std::wstring GetFilenameFromPath(const std::wstring& path) { |
381 if (path.empty() || EndsWithSeparator(path)) | 391 if (path.empty() || EndsWithSeparator(path)) |
382 return std::wstring(); | 392 return std::wstring(); |
383 | 393 |
384 return FilePath::FromWStringHack(path).BaseName().ToWStringHack(); | 394 return FilePath::FromWStringHack(path).BaseName().ToWStringHack(); |
385 } | 395 } |
386 bool GetFileSize(const std::wstring& file_path, int64* file_size) { | 396 bool GetFileSize(const std::wstring& file_path, int64* file_size) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 FilePath directory = path.DirName(); | 439 FilePath directory = path.DirName(); |
430 // If there is no separator, we will get back kCurrentDirectory. | 440 // If there is no separator, we will get back kCurrentDirectory. |
431 // In this case, clear dir. | 441 // In this case, clear dir. |
432 if (directory == path || directory.value() == FilePath::kCurrentDirectory) | 442 if (directory == path || directory.value() == FilePath::kCurrentDirectory) |
433 dir->clear(); | 443 dir->clear(); |
434 else | 444 else |
435 *dir = directory.ToWStringHack(); | 445 *dir = directory.ToWStringHack(); |
436 } | 446 } |
437 } // namespace | 447 } // namespace |
438 | 448 |
OLD | NEW |