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

Side by Side Diff: base/file_util.h

Issue 12893: Get rid of kPathSeparator on windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/file_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This file contains utility functions for dealing with the local 5 // This file contains utility functions for dealing with the local
6 // filesystem. 6 // filesystem.
7 7
8 #ifndef BASE_FILE_UTIL_H_ 8 #ifndef BASE_FILE_UTIL_H_
9 #define BASE_FILE_UTIL_H_ 9 #define BASE_FILE_UTIL_H_
10 10
(...skipping 11 matching lines...) Expand all
22 #include <stack> 22 #include <stack>
23 #include <string> 23 #include <string>
24 #include <vector> 24 #include <vector>
25 25
26 #include "base/basictypes.h" 26 #include "base/basictypes.h"
27 #include "base/file_path.h" 27 #include "base/file_path.h"
28 28
29 namespace file_util { 29 namespace file_util {
30 30
31 //----------------------------------------------------------------------------- 31 //-----------------------------------------------------------------------------
32 // Constants
33
34 #if defined(OS_WIN)
35 // The use of this constant is deprecated. Instead use file_util or FilePath
36 // functions (Append, TrimTrailingSeparator, etc.), or use
37 // FilePath::kSeparator[0].
38 extern const wchar_t kPathSeparator;
39 #endif
40
41 //-----------------------------------------------------------------------------
42 // Functions that operate purely on a path string w/o touching the filesystem: 32 // Functions that operate purely on a path string w/o touching the filesystem:
43 33
44 // Returns a vector of all of the components of the provided path. 34 // Returns a vector of all of the components of the provided path.
45 void PathComponents(const FilePath& path, 35 void PathComponents(const FilePath& path,
46 std::vector<FilePath::StringType>* components); 36 std::vector<FilePath::StringType>* components);
47 #if defined(OS_WIN) 37 #if defined(OS_WIN)
48 // Deprecated temporary compatibility function. 38 // Deprecated temporary compatibility function.
49 void PathComponents(const std::wstring& path, 39 void PathComponents(const std::wstring& path,
50 std::vector<std::wstring>* components); 40 std::vector<std::wstring>* components);
51 #endif 41 #endif
(...skipping 21 matching lines...) Expand all
73 // If 'dir' is a root directory, the result becomes empty string. 63 // If 'dir' is a root directory, the result becomes empty string.
74 // Deprecated. Use FilePath::DirName instead. 64 // Deprecated. Use FilePath::DirName instead.
75 void UpOneDirectoryOrEmpty(std::wstring* dir); 65 void UpOneDirectoryOrEmpty(std::wstring* dir);
76 66
77 // Strips the filename component from the end of 'path'. If path ends with a 67 // Strips the filename component from the end of 'path'. If path ends with a
78 // separator, then just drop the separator. 68 // separator, then just drop the separator.
79 // Deprecated. Use FilePath::DirName instead. 69 // Deprecated. Use FilePath::DirName instead.
80 void TrimFilename(std::wstring* path); 70 void TrimFilename(std::wstring* path);
81 71
82 // Returns the filename portion of 'path', without any leading \'s or /'s. 72 // Returns the filename portion of 'path', without any leading \'s or /'s.
73 // Deprecated. Use FilePath::BaseName instead.
83 std::wstring GetFilenameFromPath(const std::wstring& path); 74 std::wstring GetFilenameFromPath(const std::wstring& path);
84 75
85 // Returns "jpg" for path "C:\pics\jojo.jpg", or an empty string if 76 // Returns "jpg" for path "C:\pics\jojo.jpg", or an empty string if
86 // the file has no extension. 77 // the file has no extension.
87 std::wstring GetFileExtensionFromPath(const std::wstring& path); 78 std::wstring GetFileExtensionFromPath(const std::wstring& path);
88 79
89 // Returns 'jojo' for path "C:\pics\jojo.jpg". 80 // Returns 'jojo' for path "C:\pics\jojo.jpg".
90 std::wstring GetFilenameWithoutExtensionFromPath(const std::wstring& path); 81 std::wstring GetFilenameWithoutExtensionFromPath(const std::wstring& path);
91 82
92 // Returns the directory component of a path, without the trailing 83 // Returns the directory component of a path, without the trailing
93 // path separator, or an empty string on error. The function does not 84 // path separator, or an empty string on error. The function does not
94 // check for the existence of the path, so if it is passed a directory 85 // check for the existence of the path, so if it is passed a directory
95 // without the trailing \, it will interpret the last component of the 86 // without the trailing \, it will interpret the last component of the
96 // path as a file and chomp it. This does not support relative paths. 87 // path as a file and chomp it. This does not support relative paths.
97 // Examples: 88 // Examples:
98 // path == "C:\pics\jojo.jpg", returns "C:\pics" 89 // path == "C:\pics\jojo.jpg", returns "C:\pics"
99 // path == "C:\Windows\system32\", returns "C:\Windows\system32" 90 // path == "C:\Windows\system32\", returns "C:\Windows\system32"
100 // path == "C:\Windows\system32", returns "C:\Windows" 91 // path == "C:\Windows\system32", returns "C:\Windows"
101 std::wstring GetDirectoryFromPath(const std::wstring& path); 92 std::wstring GetDirectoryFromPath(const std::wstring& path);
102 93
103 // Appends new_ending to path, adding a separator between the two if necessary. 94 // Appends new_ending to path, adding a separator between the two if necessary.
104 void AppendToPath(std::wstring* path, const std::wstring& new_ending); 95 void AppendToPath(std::wstring* path, const std::wstring& new_ending);
105 96
106 // Convert provided relative path into an absolute path. Returns false on 97 // Convert provided relative path into an absolute path. Returns false on
107 // error. 98 // error.
108 bool AbsolutePath(FilePath* path); 99 bool AbsolutePath(FilePath* path);
109 // Deprecated temporary compatibility function. 100 // Deprecated temporary compatibility function.
110 bool AbsolutePath(std::wstring* path); 101 bool AbsolutePath(std::wstring* path);
111 102
112 // TODO(port): create FilePath versions of these functions, and remove this
113 // platform define.
114 #if defined(OS_WIN)
115 // Inserts |suffix| after the file name portion of |path| but before the 103 // Inserts |suffix| after the file name portion of |path| but before the
116 // extension. 104 // extension.
117 // Examples: 105 // Examples:
118 // path == "C:\pics\jojo.jpg" suffix == " (1)", returns "C:\pics\jojo (1).jpg" 106 // path == "C:\pics\jojo.jpg" suffix == " (1)", returns "C:\pics\jojo (1).jpg"
119 // path == "jojo.jpg" suffix == " (1)", returns "jojo (1).jpg" 107 // path == "jojo.jpg" suffix == " (1)", returns "jojo (1).jpg"
120 // path == "C:\pics\jojo" suffix == " (1)", returns "C:\pics\jojo (1)" 108 // path == "C:\pics\jojo" suffix == " (1)", returns "C:\pics\jojo (1)"
121 // path == "C:\pics.old\jojo" suffix == " (1)", returns "C:\pics.old\jojo (1)" 109 // path == "C:\pics.old\jojo" suffix == " (1)", returns "C:\pics.old\jojo (1)"
122 void InsertBeforeExtension(std::wstring* path, const std::wstring& suffix); 110 void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix);
123 111
124 // Replaces the extension of |file_name| with |extension|. If |file_name| 112 // Replaces the extension of |file_name| with |extension|. If |file_name|
125 // does not have an extension, them |extension| is added. If |extension| is 113 // does not have an extension, them |extension| is added. If |extension| is
126 // empty, then the extension is removed from |file_name|. 114 // empty, then the extension is removed from |file_name|.
115 void ReplaceExtension(FilePath* file_name,
116 const FilePath::StringType& extension);
117
118 #if defined(OS_WIN)
119 // Deprecated temporary compatibility functions.
120 void InsertBeforeExtension(std::wstring* path, const std::wstring& suffix);
127 void ReplaceExtension(std::wstring* file_name, const std::wstring& extension); 121 void ReplaceExtension(std::wstring* file_name, const std::wstring& extension);
128 #endif 122 #endif
129 123
130 // Replaces characters in 'file_name' that are illegal for file names with 124 // Replaces characters in 'file_name' that are illegal for file names with
131 // 'replace_char'. 'file_name' must not be a full or relative path, but just the 125 // 'replace_char'. 'file_name' must not be a full or relative path, but just the
132 // file name component. Any leading or trailing whitespace in 'file_name' is 126 // file name component. Any leading or trailing whitespace in 'file_name' is
133 // removed. 127 // removed.
134 // Example: 128 // Example:
135 // file_name == "bad:file*name?.txt", changed to: "bad-file-name-.txt" when 129 // file_name == "bad:file*name?.txt", changed to: "bad-file-name-.txt" when
136 // 'replace_char' is '-'. 130 // 'replace_char' is '-'.
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 415
422 // Renames a file using the SHFileOperation API to ensure that the target file 416 // Renames a file using the SHFileOperation API to ensure that the target file
423 // gets the correct default security descriptor in the new path. 417 // gets the correct default security descriptor in the new path.
424 bool RenameFileAndResetSecurityDescriptor( 418 bool RenameFileAndResetSecurityDescriptor(
425 const std::wstring& source_file_path, 419 const std::wstring& source_file_path,
426 const std::wstring& target_file_path); 420 const std::wstring& target_file_path);
427 421
428 } // namespace file_util 422 } // namespace file_util
429 423
430 #endif // BASE_FILE_UTIL_H_ 424 #endif // BASE_FILE_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698