1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-12-22 06:53:05 +00:00

Fix NormalizedView::stem to include dots

This commit is contained in:
Evil Eye 2025-12-12 22:00:21 +01:00
parent d5c7a6c6db
commit 2d33ead98d
2 changed files with 26 additions and 12 deletions

View file

@ -338,5 +338,23 @@ namespace VFS::Path
const NormalizedView value("foo"); const NormalizedView value("foo");
EXPECT_EQ(value.filename(), "foo"); EXPECT_EQ(value.filename(), "foo");
} }
TEST(VFSPathNormalizedViewTest, stemShouldOmitPathAndExtension)
{
const NormalizedView value("foo/bar.a");
EXPECT_EQ(value.stem(), "bar");
}
TEST(VFSPathNormalizedViewTest, stemShouldReturnSameValueForPathWithSingleComponent)
{
const NormalizedView value("foo");
EXPECT_EQ(value.stem(), "foo");
}
TEST(VFSPathNormalizedViewTest, stemShouldIncludeDotsBeforeTheExtension)
{
const NormalizedView value("last voyage of the u.s.s. constitution.swf");
EXPECT_EQ(value.stem(), "last voyage of the u.s.s. constitution");
}
} }
} }

View file

@ -232,18 +232,6 @@ namespace VFS::Path
return p; return p;
} }
std::string_view stem() const
{
std::string_view stem = mValue;
std::size_t pos = stem.find_last_of(separator);
if (pos != std::string_view::npos)
stem = stem.substr(pos + 1);
pos = stem.find_first_of(extensionSeparator);
if (pos != std::string_view::npos)
stem = stem.substr(0, pos);
return stem;
}
NormalizedView filename() const NormalizedView filename() const
{ {
NormalizedView result(*this); NormalizedView result(*this);
@ -252,6 +240,14 @@ namespace VFS::Path
return result; return result;
} }
std::string_view stem() const
{
std::string_view stem = filename().value();
if (const std::size_t pos = stem.find_last_of(extensionSeparator); pos != std::string_view::npos)
stem = stem.substr(0, pos);
return stem;
}
constexpr ExtensionView extension() const constexpr ExtensionView extension() const
{ {
ExtensionView result; ExtensionView result;