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

Side by Side Diff: base/files/file_path.h

Issue 4883003: Add FilePath::FinalExtension() to avoid double extensions (.tar.gz) for file selector (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment (also a rebase) Created 7 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/files/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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 217
218 // Returns a FilePath corresponding to the last path component of this 218 // Returns a FilePath corresponding to the last path component of this
219 // object, either a file or a directory. If this object already refers to 219 // object, either a file or a directory. If this object already refers to
220 // the root directory, returns a FilePath identifying the root directory; 220 // the root directory, returns a FilePath identifying the root directory;
221 // this is the only situation in which BaseName will return an absolute path. 221 // this is the only situation in which BaseName will return an absolute path.
222 FilePath BaseName() const WARN_UNUSED_RESULT; 222 FilePath BaseName() const WARN_UNUSED_RESULT;
223 223
224 // Returns ".jpg" for path "C:\pics\jojo.jpg", or an empty string if 224 // Returns ".jpg" for path "C:\pics\jojo.jpg", or an empty string if
225 // the file has no extension. If non-empty, Extension() will always start 225 // the file has no extension. If non-empty, Extension() will always start
226 // with precisely one ".". The following code should always work regardless 226 // with precisely one ".". The following code should always work regardless
227 // of the value of path. 227 // of the value of path. For common double-extensions like .tar.gz and
228 // .user.js, this method returns the combined extension. For a single
229 // component, use FinalExtension().
228 // new_path = path.RemoveExtension().value().append(path.Extension()); 230 // new_path = path.RemoveExtension().value().append(path.Extension());
229 // ASSERT(new_path == path.value()); 231 // ASSERT(new_path == path.value());
230 // NOTE: this is different from the original file_util implementation which 232 // NOTE: this is different from the original file_util implementation which
231 // returned the extension without a leading "." ("jpg" instead of ".jpg") 233 // returned the extension without a leading "." ("jpg" instead of ".jpg")
232 StringType Extension() const; 234 StringType Extension() const;
233 235
236 // Returns the path's file extension, as in Extension(), but will
237 // never return a double extension.
238 //
239 // TODO(davidben): Check all our extension-sensitive code to see if
240 // we can rename this to Extension() and the other to something like
241 // LongExtension(), defaulting to short extensions and leaving the
242 // long "extensions" to logic like file_util::GetUniquePathNumber().
243 StringType FinalExtension() const;
244
234 // Returns "C:\pics\jojo" for path "C:\pics\jojo.jpg" 245 // Returns "C:\pics\jojo" for path "C:\pics\jojo.jpg"
235 // NOTE: this is slightly different from the similar file_util implementation 246 // NOTE: this is slightly different from the similar file_util implementation
236 // which returned simply 'jojo'. 247 // which returned simply 'jojo'.
237 FilePath RemoveExtension() const WARN_UNUSED_RESULT; 248 FilePath RemoveExtension() const WARN_UNUSED_RESULT;
238 249
250 // Removes the path's file extension, as in RemoveExtension(), but
251 // ignores double extensions.
252 FilePath RemoveFinalExtension() const WARN_UNUSED_RESULT;
253
239 // Inserts |suffix| after the file name portion of |path| but before the 254 // Inserts |suffix| after the file name portion of |path| but before the
240 // extension. Returns "" if BaseName() == "." or "..". 255 // extension. Returns "" if BaseName() == "." or "..".
241 // Examples: 256 // Examples:
242 // path == "C:\pics\jojo.jpg" suffix == " (1)", returns "C:\pics\jojo (1).jpg" 257 // path == "C:\pics\jojo.jpg" suffix == " (1)", returns "C:\pics\jojo (1).jpg"
243 // path == "jojo.jpg" suffix == " (1)", returns "jojo (1).jpg" 258 // path == "jojo.jpg" suffix == " (1)", returns "jojo (1).jpg"
244 // path == "C:\pics\jojo" suffix == " (1)", returns "C:\pics\jojo (1)" 259 // path == "C:\pics\jojo" suffix == " (1)", returns "C:\pics\jojo (1)"
245 // path == "C:\pics.old\jojo" suffix == " (1)", returns "C:\pics.old\jojo (1)" 260 // path == "C:\pics.old\jojo" suffix == " (1)", returns "C:\pics.old\jojo (1)"
246 FilePath InsertBeforeExtension( 261 FilePath InsertBeforeExtension(
247 const StringType& suffix) const WARN_UNUSED_RESULT; 262 const StringType& suffix) const WARN_UNUSED_RESULT;
248 FilePath InsertBeforeExtensionASCII( 263 FilePath InsertBeforeExtensionASCII(
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 455
441 inline size_t hash_value(const base::FilePath& f) { 456 inline size_t hash_value(const base::FilePath& f) {
442 return hash_value(f.value()); 457 return hash_value(f.value());
443 } 458 }
444 459
445 #endif // COMPILER 460 #endif // COMPILER
446 461
447 } // namespace BASE_HASH_NAMESPACE 462 } // namespace BASE_HASH_NAMESPACE
448 463
449 #endif // BASE_FILES_FILE_PATH_H_ 464 #endif // BASE_FILES_FILE_PATH_H_
OLDNEW
« no previous file with comments | « no previous file | base/files/file_path.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698