From 4d4b28b07529b9a65089f0bd7318d5b83507af03 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Tue, 29 Mar 2011 20:31:36 +0300 Subject: [PATCH] Remove './' at begin of path in Path::simplifyPath. The './' is not needed at begin of path for files we check. And it only makes paths longer. This also makes it easier to match paths. --- lib/path.cpp | 7 +++++++ test/testpath.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/path.cpp b/lib/path.cpp index 0a042f95e..3fbe95367 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -47,6 +47,13 @@ std::string Path::fromNativeSeparators(const std::string &path) std::string Path::simplifyPath(const char *originalPath) { + // Skip ./ at the beginning + if (strlen(originalPath) > 2 && originalPath[0] == '.' && + originalPath[1] == '/') + { + originalPath += 2; + } + std::string subPath = ""; std::vector pathParts; for (; *originalPath; ++originalPath) diff --git a/test/testpath.cpp b/test/testpath.cpp index 8e529ee7e..340677d61 100644 --- a/test/testpath.cpp +++ b/test/testpath.cpp @@ -37,10 +37,10 @@ private: { // Path::simplifyPath() ASSERT_EQUALS("index.h", Path::simplifyPath("index.h")); + ASSERT_EQUALS("index.h", Path::simplifyPath("./index.h")); ASSERT_EQUALS("/index.h", Path::simplifyPath("/index.h")); ASSERT_EQUALS("/path/", Path::simplifyPath("/path/")); ASSERT_EQUALS("/", Path::simplifyPath("/")); - ASSERT_EQUALS("./index.h", Path::simplifyPath("./index.h")); ASSERT_EQUALS("../index.h", Path::simplifyPath("../index.h")); ASSERT_EQUALS("/index.h", Path::simplifyPath("/path/../index.h")); ASSERT_EQUALS("/index.h", Path::simplifyPath("/path/../other/../index.h"));