From ba62831f7cfd0d6111983772e7c06190e279dc03 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Fri, 21 Dec 2018 04:25:40 +0000 Subject: Implement LWG 3096: path::lexically_relative is confused by trailing slashes path("/dir/").lexically_relative("/dir"); now returns "." instead of "" llvm-svn: 349885 --- libcxx/src/filesystem/operations.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'libcxx/src/filesystem/operations.cpp') 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; -- cgit v1.2.3