summaryrefslogtreecommitdiffstats
path: root/base/file_path.h
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-09 18:26:19 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-09 18:26:19 +0000
commit235c17a4631e92a4cbd214863758165a2f573801 (patch)
tree51a7a19215a774f558744e9cedd611a86dbd6ea7 /base/file_path.h
parent7d927f8c4baddd6d358bb7f47001e99cf757d65d (diff)
downloadchromium_src-235c17a4631e92a4cbd214863758165a2f573801.zip
chromium_src-235c17a4631e92a4cbd214863758165a2f573801.tar.gz
chromium_src-235c17a4631e92a4cbd214863758165a2f573801.tar.bz2
Add implementations of various extension related methods (derived from file_util):
Extension, RemoveExtension, InsertBeforeExtension, ReplaceExtension I didn't reimplement the old file_util ones since they actually modify the FilePath in place, which isn't the style of the rest of the FilePath methods. I'll file a cleanup bug after this for callers to switch to the new methods. Review URL: http://codereview.chromium.org/17243 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7811 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_path.h')
-rw-r--r--base/file_path.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/base/file_path.h b/base/file_path.h
index 6ed9320..d80298d 100644
--- a/base/file_path.h
+++ b/base/file_path.h
@@ -109,6 +109,9 @@ class FilePath {
// A special path component meaning "the parent directory."
static const CharType kParentDirectory[];
+ // The character used to identify a file extension.
+ static const CharType kExtensionSeparator;
+
FilePath() {}
FilePath(const FilePath& that) : path_(that.path_) {}
explicit FilePath(const StringType& path) : path_(path) {}
@@ -147,6 +150,36 @@ class FilePath {
// this is the only situation in which BaseName will return an absolute path.
FilePath BaseName() const;
+ // Returns ".jpg" for path "C:\pics\jojo.jpg", or an empty string if
+ // the file has no extension. If non-empty, Extension() will always start
+ // with precisely one ".". The following code should always work regardless
+ // of the value of path.
+ // new_path = path.RemoveExtension().value().append(path.Extension());
+ // ASSERT(new_path == path.value());
+ // NOTE: this is different from the original file_util implementation which
+ // returned the extension without a leading "." ("jpg" instead of ".jpg")
+ StringType Extension() const;
+
+ // Returns "C:\pics\jojo" for path "C:\pics\jojo.jpg"
+ // NOTE: this is slightly different from the similar file_util implementation
+ // which returned simply 'jojo'.
+ FilePath RemoveExtension() const;
+
+ // Inserts |suffix| after the file name portion of |path| but before the
+ // extension. Returns "" if BaseName() == "." or "..".
+ // Examples:
+ // path == "C:\pics\jojo.jpg" suffix == " (1)", returns "C:\pics\jojo (1).jpg"
+ // path == "jojo.jpg" suffix == " (1)", returns "jojo (1).jpg"
+ // path == "C:\pics\jojo" suffix == " (1)", returns "C:\pics\jojo (1)"
+ // path == "C:\pics.old\jojo" suffix == " (1)", returns "C:\pics.old\jojo (1)"
+ FilePath InsertBeforeExtension(const StringType& suffix) const;
+
+ // Replaces the extension of |file_name| with |extension|. If |file_name|
+ // does not have an extension, them |extension| is added. If |extension| is
+ // empty, then the extension is removed from |file_name|.
+ // Returns "" if BaseName() == "." or "..".
+ FilePath ReplaceExtension(const StringType& extension) const;
+
// Returns a FilePath by appending a separator and the supplied path
// component to this object's path. Append takes care to avoid adding
// excessive separators if this object's path already ends with a separator.