Merge branch 'feature-70-path-comparison' of https://github.com/gulrak/filesystem into feature-70-path-comparison

# Conflicts:
#	include/ghc/filesystem.hpp
This commit is contained in:
Steffen Schümann 2020-10-06 21:23:13 +02:00
commit 2fe72421c5
2 changed files with 6 additions and 5 deletions

View File

@ -2695,8 +2695,8 @@ GHC_INLINE int path::compare(const path& p) const noexcept
++rnl1; ++rnl1;
++rnl2; ++rnl2;
} }
auto iter1 = _path.begin() + rnl1; auto iter1 = _path.begin() + static_cast<int>(rnl1);
auto iter2 = p._path.begin() + rnl2; auto iter2 = p._path.begin() + static_cast<int>(rnl2);
while (iter1 != _path.end() && iter2 != p._path.end() && *iter1 == *iter2) { while (iter1 != _path.end() && iter2 != p._path.end() && *iter1 == *iter2) {
++iter1; ++iter1;
++iter2; ++iter2;
@ -2719,13 +2719,13 @@ GHC_INLINE int path::compare(const path& p) const noexcept
auto rnl1 = root_name_length(); auto rnl1 = root_name_length();
auto rnl2 = p.root_name_length(); auto rnl2 = p.root_name_length();
auto rnc = detail::compare_simple_insensitive(_path.c_str(), rnl1, p._path.c_str(), rnl2); auto rnc = detail::compare_simple_insensitive(_path.c_str(), rnl1, p._path.c_str(), rnl2);
if (rnc) { if(rnc) {
return rnc; return rnc;
} }
auto p1 = _path; auto p1 = _path;
std::replace(p1.begin()+rnl1, p1.end(), '/', '\\'); std::replace(p1.begin()+static_cast<int>(rnl1), p1.end(), '/', '\\');
auto p2 = p._path; auto p2 = p._path;
std::replace(p2.begin()+rnl2, p2.end(), '/', '\\'); std::replace(p2.begin()+static_cast<int>(rnl2), p2.end(), '/', '\\');
return p1.compare(rnl1, std::string::npos, p2, rnl2, std::string::npos); return p1.compare(rnl1, std::string::npos, p2, rnl2, std::string::npos);
#else #else
return _path.compare(p._path); return _path.compare(p._path);

View File

@ -618,6 +618,7 @@ TEST_CASE("30.10.8.4.8 path compare", "[filesystem][path][fs.path.compare]")
#ifdef GHC_OS_WINDOWS #ifdef GHC_OS_WINDOWS
CHECK(fs::path("c:\\a\\b").compare("C:\\a\\b") == 0); CHECK(fs::path("c:\\a\\b").compare("C:\\a\\b") == 0);
CHECK(fs::path("c:\\a\\b").compare("d:\\a\\b") != 0);
CHECK(fs::path("c:\\a\\b").compare("C:\\A\\b") != 0); CHECK(fs::path("c:\\a\\b").compare("C:\\A\\b") != 0);
#endif #endif