summaryrefslogtreecommitdiffstats
path: root/libcxx/src/filesystem/operations.cpp
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2018-12-21 04:25:40 +0000
committerEric Fiselier <eric@efcs.ca>2018-12-21 04:25:40 +0000
commitba62831f7cfd0d6111983772e7c06190e279dc03 (patch)
tree3a9545a338912a67fd97601e8a5c23b0183ff620 /libcxx/src/filesystem/operations.cpp
parent49b183a9ecf62bc1b37e53bdddf42e6ea4ce4cd7 (diff)
downloadbcm5719-llvm-ba62831f7cfd0d6111983772e7c06190e279dc03.tar.gz
bcm5719-llvm-ba62831f7cfd0d6111983772e7c06190e279dc03.zip
Implement LWG 3096: path::lexically_relative is confused by trailing slashes
path("/dir/").lexically_relative("/dir"); now returns "." instead of "" llvm-svn: 349885
Diffstat (limited to 'libcxx/src/filesystem/operations.cpp')
-rw-r--r--libcxx/src/filesystem/operations.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp
index 0b79ef1cdac..e3bbc7b64b8 100644
--- a/libcxx/src/filesystem/operations.cpp
+++ b/libcxx/src/filesystem/operations.cpp
@@ -1478,7 +1478,7 @@ static int DetermineLexicalElementCount(PathParser PP) {
auto Elem = *PP;
if (Elem == "..")
--Count;
- else if (Elem != ".")
+ else if (Elem != "." && Elem != "")
++Count;
}
return Count;
@@ -1492,8 +1492,7 @@ path path::lexically_relative(const path& base) const {
return PP.State != PPBase.State &&
(PP.inRootPath() || PPBase.inRootPath());
};
- if (PP.State == PathParser::PS_InRootName &&
- PPBase.State == PathParser::PS_InRootName) {
+ if (PP.inRootName() && PPBase.inRootName()) {
if (*PP != *PPBase)
return {};
} else if (CheckIterMismatchAtBase())
@@ -1525,6 +1524,10 @@ path path::lexically_relative(const path& base) const {
if (ElemCount < 0)
return {};
+ // if n == 0 and (a == end() || a->empty()), returns path("."); otherwise
+ if (ElemCount == 0 && (PP.atEnd() || *PP == ""))
+ return ".";
+
// return a path constructed with 'n' dot-dot elements, followed by the the
// elements of '*this' after the mismatch.
path Result;
OpenPOWER on IntegriCloud