[llvm-commits] [llvm] r120514 - in /llvm/trunk: lib/Support/PathV2.cpp unittests/Support/Path.cpp
Michael J. Spencer
bigcheesegs at gmail.com
Tue Nov 30 16:52:55 PST 2010
Author: mspencer
Date: Tue Nov 30 18:52:55 2010
New Revision: 120514
URL: http://llvm.org/viewvc/llvm-project?rev=120514&view=rev
Log:
Support/PathV2: Add replace_extension 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=120514&r1=120513&r2=120514&view=diff
==============================================================================
--- llvm/trunk/lib/Support/PathV2.cpp (original)
+++ llvm/trunk/lib/Support/PathV2.cpp Tue Nov 30 18:52:55 2010
@@ -511,6 +511,26 @@
return make_error_code(errc::success);
}
+error_code replace_extension(SmallVectorImpl<char> &path,
+ const Twine &extension) {
+ StringRef p(path.begin(), path.size());
+ SmallString<32> ext_storage;
+ StringRef ext = extension.toStringRef(ext_storage);
+
+ // Erase existing extension.
+ size_t pos = p.find_last_of('.');
+ if (pos != StringRef::npos && pos >= filename_pos(p))
+ path.set_size(pos);
+
+ // Append '.' if needed.
+ if (ext.size() > 0 && ext[0] != '.')
+ path.push_back('.');
+
+ // Append extension.
+ path.append(ext.begin(), ext.end());
+ 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=120514&r1=120513&r2=120514&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Tue Nov 30 18:52:55 2010
@@ -103,6 +103,10 @@
if (error_code ec = sys::path::remove_filename(temp_store))
ASSERT_FALSE(ec.message().c_str());
outs() << " remove_filename: " << temp_store << '\n';
+ temp_store = *i;
+ if (error_code ec = sys::path::replace_extension(temp_store, "ext"))
+ ASSERT_FALSE(ec.message().c_str());
+ outs() << " replace_extension: " << temp_store << '\n';
outs().flush();
}
More information about the llvm-commits
mailing list