mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 14:06:16 +02:00
baseNameOf(): Remove all trailing slashes
This commit is contained in:
parent
754a15e2db
commit
9884018dfa
2 changed files with 11 additions and 1 deletions
|
@ -128,7 +128,7 @@ std::string_view baseNameOf(std::string_view path)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
auto last = path.size() - 1;
|
auto last = path.size() - 1;
|
||||||
if (path[last] == '/' && last > 0)
|
while (last > 0 && path[last] == '/')
|
||||||
last -= 1;
|
last -= 1;
|
||||||
|
|
||||||
auto pos = path.rfind('/', last);
|
auto pos = path.rfind('/', last);
|
||||||
|
|
|
@ -151,6 +151,16 @@ namespace nix {
|
||||||
ASSERT_EQ(p1, "dir");
|
ASSERT_EQ(p1, "dir");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(baseNameOf, trailingSlashes) {
|
||||||
|
auto p1 = baseNameOf("/dir//");
|
||||||
|
ASSERT_EQ(p1, "dir");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(baseNameOf, absoluteNothingSlashNothing) {
|
||||||
|
auto p1 = baseNameOf("//");
|
||||||
|
ASSERT_EQ(p1, "");
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
* isInDir
|
* isInDir
|
||||||
* --------------------------------------------------------------------------*/
|
* --------------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in a new issue