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; |