Support/PathV2: Add extension implementation.
llvm-svn: 120550
diff --git a/llvm/lib/Support/PathV2.cpp b/llvm/lib/Support/PathV2.cpp
index e360e9c..47e59dd 100644
--- a/llvm/lib/Support/PathV2.cpp
+++ b/llvm/lib/Support/PathV2.cpp
@@ -574,6 +574,22 @@
return make_error_code(errc::success);
}
+error_code extension(const StringRef &path, StringRef &result) {
+ StringRef fname;
+ if (error_code ec = filename(path, fname)) return ec;
+ size_t pos = fname.find_last_of('.');
+ if (pos == StringRef::npos)
+ result = StringRef();
+ else
+ if ((fname.size() == 1 && fname == ".") ||
+ (fname.size() == 2 && fname == ".."))
+ result = StringRef();
+ else
+ result = StringRef(fname.begin() + pos, fname.size() - pos);
+
+ return make_error_code(errc::success);
+}
+
}
}
}