Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3159)

Unified Diff: base/file_util_win.cc

Issue 12489: Remove file_util::kPathSeparator from posix. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/file_util_unittest.cc ('k') | chrome/browser/safe_browsing/safe_browsing_database_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_win.cc
===================================================================
--- base/file_util_win.cc (revision 6039)
+++ base/file_util_win.cc (working copy)
@@ -19,7 +19,13 @@
namespace file_util {
const wchar_t kPathSeparator = L'\\';
+const wchar_t kExtensionSeparator = L'.';
+void PathComponents(const std::wstring& path,
+ std::vector<std::wstring>* components) {
+ PathComponents(FilePath(path), components);
+}
+
std::wstring GetDirectoryFromPath(const std::wstring& path) {
wchar_t path_buffer[MAX_PATH];
wchar_t* file_ptr = NULL;
@@ -40,7 +46,56 @@
*path = FilePath(file_path_buf);
return true;
}
-
+
+void InsertBeforeExtension(std::wstring* path, const std::wstring& suffix) {
+ DCHECK(path);
+
+ const std::wstring::size_type last_dot = path->rfind(kExtensionSeparator);
+ const std::wstring::size_type last_sep = path->rfind(kPathSeparator);
+
+ if (last_dot == std::wstring::npos ||
+ (last_sep != std::wstring::npos && last_dot < last_sep)) {
+ // The path looks something like "C:\pics.old\jojo" or "C:\pics\jojo".
+ // We should just append the suffix to the entire path.
+ path->append(suffix);
+ return;
+ }
+
+ path->insert(last_dot, suffix);
+}
+
+// Appends the extension to file adding a '.' if extension doesn't contain one.
+// This does nothing if extension is empty or '.'. This is used internally by
+// ReplaceExtension.
+static void AppendExtension(const std::wstring& extension,
+ std::wstring* file) {
+ if (!extension.empty() && extension != L".") {
+ if (extension[0] != L'.')
+ file->append(L".");
+ file->append(extension);
+ }
+}
+
+void ReplaceExtension(std::wstring* file_name, const std::wstring& extension) {
+ const std::wstring::size_type last_dot = file_name->rfind(L'.');
+ if (last_dot == std::wstring::npos) {
+ // No extension, just append the supplied extension.
+ AppendExtension(extension, file_name);
+ return;
+ }
+ const std::wstring::size_type last_separator =
+ file_name->rfind(kPathSeparator);
+ if (last_separator != std::wstring::npos && last_dot < last_separator) {
+ // File name doesn't have extension, but one of the directories does; don't
+ // replace it, just append the supplied extension. For example
+ // 'c:\tmp.bar\foo'.
+ AppendExtension(extension, file_name);
+ return;
+ }
+ std::wstring result = file_name->substr(0, last_dot);
+ AppendExtension(extension, &result);
+ file_name->swap(result);
+}
int CountFilesCreatedAfter(const std::wstring& path,
const FILETIME& comparison_time) {
int file_count = 0;
« no previous file with comments | « base/file_util_unittest.cc ('k') | chrome/browser/safe_browsing/safe_browsing_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698