diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-01 03:18:33 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-01 03:18:33 +0000 |
commit | 34ab1f6087bc0da1df0e3a73ac99762ef070d419 (patch) | |
tree | e36ef5418584577500d15fbc6c5bca49836218e5 | |
parent | a9793559942dd055d460f8e3d438b49889eb4f5c (diff) |
Support/PathV2: Add stem implementation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120547 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Support/PathV2.cpp | 16 | ||||
-rw-r--r-- | unittests/Support/Path.cpp | 7 |
2 files changed, 23 insertions, 0 deletions
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); +} + } } } diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp index 0dae960f48..70cf213f19 100644 --- a/unittests/Support/Path.cpp +++ b/unittests/Support/Path.cpp @@ -97,6 +97,9 @@ TEST(Support, Path) { if (error_code ec = sys::path::filename(*i, res)) ASSERT_FALSE(ec.message().c_str()); outs() << " filename: " << res << '\n'; + if (error_code ec = sys::path::stem(*i, res)) + ASSERT_FALSE(ec.message().c_str()); + outs() << " stem: " << res << '\n'; temp_store = *i; if (error_code ec = sys::path::make_absolute(temp_store)) @@ -110,6 +113,10 @@ TEST(Support, Path) { if (error_code ec = sys::path::replace_extension(temp_store, "ext")) ASSERT_FALSE(ec.message().c_str()); outs() << " replace_extension: " << temp_store << '\n'; + if (error_code ec = sys::path::stem( + StringRef(temp_store.begin(), temp_store.size()), res)) + ASSERT_FALSE(ec.message().c_str()); + outs() << " stem: " << res << '\n'; if (error_code ec = sys::path::native(*i, temp_store)) ASSERT_FALSE(ec.message().c_str()); outs() << " native: " << temp_store << '\n'; |