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

Unified Diff: base/files/file_path.cc

Issue 863583002: Add FilePath::FinalExtension and RemoveFinalExtension (Closed) Base URL: https://chromium.googlesource.com/chromium/mini_chromium@master
Patch Set: simplify Created 5 years, 11 months 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/files/file_path.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_path.cc
diff --git a/base/files/file_path.cc b/base/files/file_path.cc
index 90cf40f4da8453396bae2e473c9865aaa3f27ab2..f8fb8b479469e39d64d9a32795a59f9e77297b15 100644
--- a/base/files/file_path.cc
+++ b/base/files/file_path.cc
@@ -18,6 +18,8 @@ const FilePath::CharType FilePath::kSeparators[] = FILE_PATH_LITERAL("/");
#endif // FILE_PATH_USES_WIN_SEPARATORS
const FilePath::CharType FilePath::kCurrentDirectory[] = FILE_PATH_LITERAL(".");
+const FilePath::CharType FilePath::kParentDirectory[] = FILE_PATH_LITERAL("..");
+const FilePath::CharType FilePath::kExtensionSeparator = FILE_PATH_LITERAL('.');
typedef FilePath::StringType StringType;
@@ -190,6 +192,25 @@ FilePath FilePath::BaseName() const {
return new_path;
}
+StringType FilePath::FinalExtension() const {
+ StringType base(BaseName().value());
+ // Special case "." and ".."
+ if (base == FilePath::kCurrentDirectory || base == FilePath::kParentDirectory)
+ return StringType();
+ const StringType::size_type dot = base.rfind(FilePath::kExtensionSeparator);
+ if (dot == StringType::npos)
+ return StringType();
+
+ return base.substr(dot, StringType::npos);
+}
+
+FilePath FilePath::RemoveFinalExtension() const {
+ StringType extension = FinalExtension();
+ if (FinalExtension().empty())
+ return *this;
+ return FilePath(path_.substr(0, path_.size() - extension.size()));
+}
+
FilePath FilePath::Append(const StringType& component) const {
const StringType* appended = &component;
StringType without_nuls;
« no previous file with comments | « base/files/file_path.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698