From 34ab1f6087bc0da1df0e3a73ac99762ef070d419 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Wed, 1 Dec 2010 03:18:33 +0000 Subject: Support/PathV2: Add stem implementation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120547 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/PathV2.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/Support/PathV2.cpp') diff --git a/lib/Support/PathV2.cpp b/lib/Support/PathV2.cpp index 9c343ea006..e360e9cd1f 100644 --- a/lib/Support/PathV2.cpp +++ b/lib/Support/PathV2.cpp @@ -558,6 +558,22 @@ error_code filename(const StringRef &path, StringRef &result) { return make_error_code(errc::success); } +error_code stem(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 = fname; + else + if ((fname.size() == 1 && fname == ".") || + (fname.size() == 2 && fname == "..")) + result = fname; + else + result = StringRef(fname.begin(), pos); + + return make_error_code(errc::success); +} + } } } -- cgit v1.2.3-18-g5258