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

Side by Side Diff: base/file_path.h

Issue 12907: Make FilePath accept FilePath as Append parameter. (Closed) Base URL: http://src.chromium.org/svn/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 | « base/directory_watcher_unittest.cc ('k') | base/file_path.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) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 // FilePath is a container for pathnames stored in a platform's native string 5 // FilePath is a container for pathnames stored in a platform's native string
6 // type, providing containers for manipulation in according with the 6 // type, providing containers for manipulation in according with the
7 // platform's conventions for pathnames. It supports the following path 7 // platform's conventions for pathnames. It supports the following path
8 // types: 8 // types:
9 // 9 //
10 // POSIX Windows 10 // POSIX Windows
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // this is the only situation in which BaseName will return an absolute path. 139 // this is the only situation in which BaseName will return an absolute path.
140 FilePath BaseName() const; 140 FilePath BaseName() const;
141 141
142 // Returns a FilePath by appending a separator and the supplied path 142 // Returns a FilePath by appending a separator and the supplied path
143 // component to this object's path. Append takes care to avoid adding 143 // component to this object's path. Append takes care to avoid adding
144 // excessive separators if this object's path already ends with a separator. 144 // excessive separators if this object's path already ends with a separator.
145 // If this object's path is kCurrentDirectory, a new FilePath corresponding 145 // If this object's path is kCurrentDirectory, a new FilePath corresponding
146 // only to |component| is returned. |component| must be a relative path; 146 // only to |component| is returned. |component| must be a relative path;
147 // it is an error to pass an absolute path. 147 // it is an error to pass an absolute path.
148 FilePath Append(const StringType& component) const WARN_UNUSED_RESULT; 148 FilePath Append(const StringType& component) const WARN_UNUSED_RESULT;
149 FilePath Append(const FilePath& component) const WARN_UNUSED_RESULT;
149 150
150 // Returns true if this FilePath contains an absolute path. On Windows, an 151 // Returns true if this FilePath contains an absolute path. On Windows, an
151 // absolute path begins with either a drive letter specification followed by 152 // absolute path begins with either a drive letter specification followed by
152 // a separator character, or with two separator characters. On POSIX 153 // a separator character, or with two separator characters. On POSIX
153 // platforms, an absolute path begins with a separator character. 154 // platforms, an absolute path begins with a separator character.
154 bool IsAbsolute() const; 155 bool IsAbsolute() const;
155 156
156 // Older Chromium code assumes that paths are always wstrings. 157 // Older Chromium code assumes that paths are always wstrings.
157 // This function converts a wstring to a FilePath, and is useful to smooth 158 // This function converts a wstring to a FilePath, and is useful to smooth
158 // porting that old code to the FilePath API. 159 // porting that old code to the FilePath API.
159 // It has "Hack" in its name so people feel bad about using it. 160 // It has "Hack" in its name so people feel bad about using it.
160 // TODO(port): remove these functions. 161 // TODO(port): remove these functions.
161 static FilePath FromWStringHack(const std::wstring& wstring); 162 static FilePath FromWStringHack(const std::wstring& wstring);
162 163
163 // Older Chromium code assumes that paths are always wstrings. 164 // Older Chromium code assumes that paths are always wstrings.
164 // This function produces a wstring from a FilePath, and is useful to smooth 165 // This function produces a wstring from a FilePath, and is useful to smooth
165 // porting that old code to the FilePath API. 166 // porting that old code to the FilePath API.
166 // It has "Hack" in its name so people feel bad about using it. 167 // It has "Hack" in its name so people feel bad about using it.
167 // TODO(port): remove these functions. 168 // TODO(port): remove these functions.
168 std::wstring ToWStringHack() const; 169 std::wstring ToWStringHack() const;
169 170
170 private: 171 private:
171 // If this FilePath contains a drive letter specification, returns the
172 // position of the last character of the drive letter specification,
173 // otherwise returns npos. This can only be true on Windows, when a pathname
174 // begins with a letter followed by a colon. On other platforms, this always
175 // returns npos.
176 StringType::size_type FindDriveLetter() const;
177
178 // Remove trailing separators from this object. If the path is absolute, it 172 // Remove trailing separators from this object. If the path is absolute, it
179 // will never be stripped any more than to refer to the absolute root 173 // will never be stripped any more than to refer to the absolute root
180 // directory, so "////" will become "/", not "". A leading pair of 174 // directory, so "////" will become "/", not "". A leading pair of
181 // separators is never stripped, to support alternate roots. This is used to 175 // separators is never stripped, to support alternate roots. This is used to
182 // support UNC paths on Windows. 176 // support UNC paths on Windows.
183 void StripTrailingSeparators(); 177 void StripTrailingSeparators();
184 178
185 StringType path_; 179 StringType path_;
186 }; 180 };
187 181
188 // Macros for string literal initialization of FilePath::CharType[]. 182 // Macros for string literal initialization of FilePath::CharType[].
189 #if defined(OS_POSIX) 183 #if defined(OS_POSIX)
190 #define FILE_PATH_LITERAL(x) x 184 #define FILE_PATH_LITERAL(x) x
191 #elif defined(OS_WIN) 185 #elif defined(OS_WIN)
192 #define FILE_PATH_LITERAL(x) L ## x 186 #define FILE_PATH_LITERAL(x) L ## x
193 #endif // OS_WIN 187 #endif // OS_WIN
194 188
195 #endif // BASE_FILE_PATH_H_ 189 #endif // BASE_FILE_PATH_H_
OLDNEW
« no previous file with comments | « base/directory_watcher_unittest.cc ('k') | base/file_path.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698