Skip to content

Commit

Permalink
refs #70, fix for non LWG2936 mode and updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gulrak committed Oct 6, 2020
1 parent 56b5e7a commit 3cd5bc6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,18 @@ to the expected behavior.
### v1.3.5 (WIP)
* Refactoring for [#73](https://github.com/gulrak/filesystem/issues/68), enhanced performance
* Refactoring for [#73](https://github.com/gulrak/filesystem/issues/73), enhanced performance
in path handling. the changes lead to much fewer path/string creations or copies, speeding
up large directory iteration or operations on many path instances.
* Bugfix for [#72](https://github.com/gulrak/filesystem/issues/72), the `TestAllocator` in
`filesystem_test.cpp` was completed to fulfill the requirements to build on CentOS 7 with
`devtoolset-9`. CentOS 7 and CentOS 8 are now part of the CI builds.
* Bugfix for [#70](https://github.com/gulrak/filesystem/issues/70), root names are now case
insensitive on Windows. This fix also adds the new behaviour switch `LWG_2936_BEHAVIOUR`
that allows to enable post C++17 `fs::path::compare` behaviour, where the comparison is as
if it was an element wise path comparison as described in
[LWG 2936](https://cplusplus.github.io/LWG/issue2936) and C++20 `[fs.path.compare]`.
It is default off in v1.3.6 and will be default starting from v1.4.0 as it changes ordering.
### [v1.3.4](https://github.com/gulrak/filesystem/releases/tag/v1.3.4)
Expand Down
23 changes: 3 additions & 20 deletions include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2719,6 +2719,9 @@ GHC_INLINE int path::compare(const path& p) const noexcept
auto rnl1 = root_name_length();
auto rnl2 = p.root_name_length();
auto rnc = detail::compare_simple_insensitive(_path.c_str(), rnl1, p._path.c_str(), rnl2);
if (rnc) {
return rnc;
}
auto p1 = _path;
std::replace(p1.begin()+rnl1, p1.end(), '/', '\\');
auto p2 = p._path;
Expand Down Expand Up @@ -3191,11 +3194,7 @@ GHC_INLINE size_t hash_value(const path& p) noexcept

GHC_INLINE bool operator==(const path& lhs, const path& rhs) noexcept
{
#ifdef LWG_2936_BEHAVIOUR
return lhs.compare(rhs) == 0;
#else
return lhs.generic_string() == rhs.generic_string();
#endif
}

GHC_INLINE bool operator!=(const path& lhs, const path& rhs) noexcept
Expand All @@ -3205,38 +3204,22 @@ GHC_INLINE bool operator!=(const path& lhs, const path& rhs) noexcept

GHC_INLINE bool operator<(const path& lhs, const path& rhs) noexcept
{
#ifdef LWG_2936_BEHAVIOUR
return lhs.compare(rhs) < 0;
#else
return lhs.generic_string() < rhs.generic_string();
#endif
}

GHC_INLINE bool operator<=(const path& lhs, const path& rhs) noexcept
{
#ifdef LWG_2936_BEHAVIOUR
return lhs.compare(rhs) <= 0;
#else
return lhs.generic_string() <= rhs.generic_string();
#endif
}

GHC_INLINE bool operator>(const path& lhs, const path& rhs) noexcept
{
#ifdef LWG_2936_BEHAVIOUR
return lhs.compare(rhs) > 0;
#else
return lhs.generic_string() > rhs.generic_string();
#endif
}

GHC_INLINE bool operator>=(const path& lhs, const path& rhs) noexcept
{
#ifdef LWG_2936_BEHAVIOUR
return lhs.compare(rhs) >= 0;
#else
return lhs.generic_string() >= rhs.generic_string();
#endif
}

GHC_INLINE path operator/(const path& lhs, const path& rhs)
Expand Down
14 changes: 14 additions & 0 deletions test/filesystem_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,8 @@ TEST_CASE("30.10.8.4.11 path generation", "[filesystem][path][fs.path.gen]")
CHECK(fs::path("c:/foo").lexically_relative("/bar") == "");
CHECK(fs::path("c:foo").lexically_relative("c:/bar") == "");
CHECK(fs::path("foo").lexically_relative("/bar") == "");
CHECK(fs::path("c:/foo/bar.txt").lexically_relative("c:/foo/") == "bar.txt");
CHECK(fs::path("c:/foo/bar.txt").lexically_relative("C:/foo/") == "bar.txt");
#else
CHECK(fs::path("/foo").lexically_relative("bar") == "");
CHECK(fs::path("foo").lexically_relative("/bar") == "");
Expand Down Expand Up @@ -972,7 +974,13 @@ TEST_CASE("30.10.8.5 path iterators", "[filesystem][path][fs.path.itr]")
CHECK("/,foo," == iterateResult(fs::path("/foo/")));
CHECK("foo,bar" == iterateResult(fs::path("foo/bar")));
CHECK("/,foo,bar" == iterateResult(fs::path("/foo/bar")));
#ifndef USE_STD_FS
// ghc::filesystem enforces redundant slashes to be reduced to one
CHECK("/,foo,bar" == iterateResult(fs::path("///foo/bar")));
#else
// typically std::filesystem keeps them
CHECK("///,foo,bar" == iterateResult(fs::path("///foo/bar")));
#endif
CHECK("/,foo,bar," == iterateResult(fs::path("/foo/bar///")));
CHECK("foo,.,bar,..," == iterateResult(fs::path("foo/.///bar/../")));
#ifdef GHC_OS_WINDOWS
Expand All @@ -989,7 +997,13 @@ TEST_CASE("30.10.8.5 path iterators", "[filesystem][path][fs.path.itr]")
CHECK(",foo,/" == reverseIterateResult(fs::path("/foo/")));
CHECK("bar,foo" == reverseIterateResult(fs::path("foo/bar")));
CHECK("bar,foo,/" == reverseIterateResult(fs::path("/foo/bar")));
#ifndef USE_STD_FS
// ghc::filesystem enforces redundant slashes to be reduced to one
CHECK("bar,foo,/" == reverseIterateResult(fs::path("///foo/bar")));
#else
// typically std::filesystem keeps them
CHECK("bar,foo,///" == reverseIterateResult(fs::path("///foo/bar")));
#endif
CHECK(",bar,foo,/" == reverseIterateResult(fs::path("/foo/bar///")));
CHECK(",..,bar,.,foo" == reverseIterateResult(fs::path("foo/.///bar/../")));
#ifdef GHC_OS_WINDOWS
Expand Down

0 comments on commit 3cd5bc6

Please sign in to comment.