Support/PathV2: Add remove_filename implementation.

llvm-svn: 120513
This commit is contained in:
Michael J. Spencer 2010-12-01 00:52:28 +00:00
parent 4915f56669
commit 9c594095a6
3 changed files with 13 additions and 1 deletions

View File

@ -140,7 +140,7 @@ error_code make_absolute(SmallVectorImpl<char> &path);
/// @brief Remove the last component from \a path if it exists.
///
/// directory/filename.cpp => directory/
/// directory/ => directory/
/// directory/ => directory
///
/// @param path A path that is modified to not have a file component.
/// @returns errc::success if \a path's file name has been removed (or there was

View File

@ -503,6 +503,14 @@ error_code parent_path(const StringRef &path, StringRef &result) {
return make_error_code(errc::success);
}
error_code remove_filename(SmallVectorImpl<char> &path) {
size_t end_pos = parent_path_end(StringRef(path.begin(), path.size()));
if (end_pos == StringRef::npos)
return make_error_code(errc::success);
path.set_size(end_pos);
return make_error_code(errc::success);
}
}
}
}

View File

@ -99,6 +99,10 @@ TEST(Support, Path) {
if (error_code ec = sys::path::make_absolute(temp_store))
ASSERT_FALSE(ec.message().c_str());
outs() << " make_absolute: " << temp_store << '\n';
temp_store = *i;
if (error_code ec = sys::path::remove_filename(temp_store))
ASSERT_FALSE(ec.message().c_str());
outs() << " remove_filename: " << temp_store << '\n';
outs().flush();
}