implement Path::dirname()
This commit is contained in:
parent
eb12420155
commit
49ccad5ed4
@ -16,8 +16,26 @@ namespace jes
|
|||||||
|
|
||||||
Path Path::dirname()
|
Path Path::dirname()
|
||||||
{
|
{
|
||||||
// TODO
|
size_t i = m_path.size() - 1;
|
||||||
return "";
|
while (m_path[i] == '/')
|
||||||
|
{
|
||||||
|
if (i == 0)
|
||||||
|
return "/";
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
while (m_path[i] != '/')
|
||||||
|
{
|
||||||
|
if (i == 0)
|
||||||
|
return ".";
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
while (m_path[i] == '/')
|
||||||
|
{
|
||||||
|
if (i == 0)
|
||||||
|
return "/";
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
return std::string(m_path, 0, i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Path Path::join(const Path & other)
|
Path Path::join(const Path & other)
|
||||||
|
@ -27,3 +27,14 @@ TEST(PathTest, joins_two_paths_together)
|
|||||||
EXPECT_EQ("C:/foo/../baz", Path("C:\\foo").join("../baz").to_s());
|
EXPECT_EQ("C:/foo/../baz", Path("C:\\foo").join("../baz").to_s());
|
||||||
EXPECT_EQ("/xyz/f.txt", Path("/xyz/").join("f.txt").to_s());
|
EXPECT_EQ("/xyz/f.txt", Path("/xyz/").join("f.txt").to_s());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(PathTest, dirname)
|
||||||
|
{
|
||||||
|
EXPECT_EQ("/one/two", Path("/one/two/f.c").dirname().to_s());
|
||||||
|
EXPECT_EQ("C:/a", Path("C:\\a\\b\\").dirname().to_s());
|
||||||
|
EXPECT_EQ("/", Path("/").dirname().to_s());
|
||||||
|
EXPECT_EQ("/", Path("///foo").dirname().to_s());
|
||||||
|
EXPECT_EQ(".", Path("file.txt").dirname().to_s());
|
||||||
|
EXPECT_EQ(".", Path("folder//").dirname().to_s());
|
||||||
|
EXPECT_EQ("a", Path("a/b").dirname().to_s());
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user