Skip to content

Commit

Permalink
refs #33, added test for trailing preferred seperator on last '..' fo…
Browse files Browse the repository at this point in the history
…r path::lexically_normal
  • Loading branch information
gulrak committed Oct 23, 2019
1 parent 8302328 commit cf51888
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2644,6 +2644,12 @@ GHC_INLINE path path::lexically_normal() const
if (dest.empty()) {
dest = ".";
}
else {
static const path suffix[2] = {"", ".."};
if(std::equal(std::reverse_iterator<path::const_iterator>(dest.end()), std::reverse_iterator<path::const_iterator>(dest.begin()), suffix)) {
dest._path.pop_back();
}
}
return dest;
}

Expand Down
2 changes: 2 additions & 0 deletions test/filesystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -873,10 +873,12 @@ TEST_CASE("30.10.8.4.11 path generation", "[filesystem][path][fs.path.gen]")
CHECK(fs::path("foo/..").lexically_normal() == ".");
CHECK(fs::path("ab/cd/ef/../../qw").lexically_normal() == "ab/qw");
CHECK(fs::path("a/b/../../../c").lexically_normal() == "../c");
CHECK(fs::path("../").lexically_normal() == "..");
#ifdef GHC_OS_WINDOWS
CHECK(fs::path("\\/\\///\\/").lexically_normal() == "/");
CHECK(fs::path("a/b/..\\//..///\\/../c\\\\/").lexically_normal() == "../c/");
CHECK(fs::path("..a/b/..\\//..///\\/../c\\\\/").lexically_normal() == "../c/");
CHECK(fs::path("..\\").lexically_normal() == "..");
#endif

// lexically_relative()
Expand Down

0 comments on commit cf51888

Please sign in to comment.