mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-07 16:54:48 +00:00
Support/PathV2: Add extension implementation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120550 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
28cd48fffb
commit
5265f22f45
@ -574,6 +574,22 @@ error_code stem(const StringRef &path, StringRef &result) {
|
|||||||
return make_error_code(errc::success);
|
return make_error_code(errc::success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_code extension(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 = StringRef();
|
||||||
|
else
|
||||||
|
if ((fname.size() == 1 && fname == ".") ||
|
||||||
|
(fname.size() == 2 && fname == ".."))
|
||||||
|
result = StringRef();
|
||||||
|
else
|
||||||
|
result = StringRef(fname.begin() + pos, fname.size() - pos);
|
||||||
|
|
||||||
|
return make_error_code(errc::success);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,9 @@ TEST(Support, Path) {
|
|||||||
if (error_code ec = sys::path::stem(*i, res))
|
if (error_code ec = sys::path::stem(*i, res))
|
||||||
ASSERT_FALSE(ec.message().c_str());
|
ASSERT_FALSE(ec.message().c_str());
|
||||||
outs() << " stem: " << res << '\n';
|
outs() << " stem: " << res << '\n';
|
||||||
|
if (error_code ec = sys::path::extension(*i, res))
|
||||||
|
ASSERT_FALSE(ec.message().c_str());
|
||||||
|
outs() << " stem: " << res << '\n';
|
||||||
|
|
||||||
temp_store = *i;
|
temp_store = *i;
|
||||||
if (error_code ec = sys::path::make_absolute(temp_store))
|
if (error_code ec = sys::path::make_absolute(temp_store))
|
||||||
@ -113,10 +116,17 @@ TEST(Support, Path) {
|
|||||||
if (error_code ec = sys::path::replace_extension(temp_store, "ext"))
|
if (error_code ec = sys::path::replace_extension(temp_store, "ext"))
|
||||||
ASSERT_FALSE(ec.message().c_str());
|
ASSERT_FALSE(ec.message().c_str());
|
||||||
outs() << " replace_extension: " << temp_store << '\n';
|
outs() << " replace_extension: " << temp_store << '\n';
|
||||||
|
StringRef stem, ext;
|
||||||
if (error_code ec = sys::path::stem(
|
if (error_code ec = sys::path::stem(
|
||||||
StringRef(temp_store.begin(), temp_store.size()), res))
|
StringRef(temp_store.begin(), temp_store.size()), stem))
|
||||||
ASSERT_FALSE(ec.message().c_str());
|
ASSERT_FALSE(ec.message().c_str());
|
||||||
outs() << " stem: " << res << '\n';
|
outs() << " stem: " << stem << '\n';
|
||||||
|
if (error_code ec = sys::path::extension(
|
||||||
|
StringRef(temp_store.begin(), temp_store.size()), ext))
|
||||||
|
ASSERT_FALSE(ec.message().c_str());
|
||||||
|
outs() << " extension: " << ext << '\n';
|
||||||
|
EXPECT_EQ(*(--sys::path::end(
|
||||||
|
StringRef(temp_store.begin(), temp_store.size()))), (stem + ext).str());
|
||||||
if (error_code ec = sys::path::native(*i, temp_store))
|
if (error_code ec = sys::path::native(*i, temp_store))
|
||||||
ASSERT_FALSE(ec.message().c_str());
|
ASSERT_FALSE(ec.message().c_str());
|
||||||
outs() << " native: " << temp_store << '\n';
|
outs() << " native: " << temp_store << '\n';
|
||||||
|
Loading…
Reference in New Issue
Block a user