Also mention "basename" and "dirname" in Path.h since I tried
to find these functions by looking for these strings. It might
help others find them faster if the comments contain these strings.
No behavior change.
Differential Revision: https://reviews.llvm.org/D69458
// Drop directory components and replace extension with ".exe" or ".dll".
static std::string getOutputPath(StringRef path) {
- auto p = path.find_last_of("\\/");
- StringRef s = (p == StringRef::npos) ? path : path.substr(p + 1);
- const char* e = config->dll ? ".dll" : ".exe";
- return (s.substr(0, s.rfind('.')) + e).str();
+ return (sys::path::stem(path) + (config->dll ? ".dll" : ".exe")).str();
}
// Returns true if S matches /crtend.?\.o$/.
/// Remove the last component from \a path unless it is the root dir.
///
+/// Similar to the POSIX "dirname" utility.
+///
/// @code
/// directory/filename.cpp => directory/
/// directory/ => directory
///
/// @param path Input path.
/// @result The filename part of \a path. This is defined as the last component
-/// of \a path.
+/// of \a path. Similar to the POSIX "basename" utility.
StringRef filename(StringRef path, Style style = Style::native);
/// Get stem.