[llvm-commits] [llvm] r120547 - in /llvm/trunk: lib/Support/PathV2.cpp unittests/Support/Path.cpp

Michael J. Spencer bigcheesegs at gmail.com
Tue Nov 30 19:18:33 PST 2010


Author: mspencer
Date: Tue Nov 30 21:18:33 2010
New Revision: 120547

URL: http://llvm.org/viewvc/llvm-project?rev=120547&view=rev
Log:
Support/PathV2: Add stem implementation.

Modified:
    llvm/trunk/lib/Support/PathV2.cpp
    llvm/trunk/unittests/Support/Path.cpp

Modified: llvm/trunk/lib/Support/PathV2.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PathV2.cpp?rev=120547&r1=120546&r2=120547&view=diff
==============================================================================
--- llvm/trunk/lib/Support/PathV2.cpp (original)
+++ llvm/trunk/lib/Support/PathV2.cpp Tue Nov 30 21:18:33 2010
@@ -558,6 +558,22 @@
   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);
+}
+
 }
 }
 }

Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=120547&r1=120546&r2=120547&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Tue Nov 30 21:18:33 2010
@@ -97,6 +97,9 @@
     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 @@
     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';





More information about the llvm-commits mailing list