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.
This commit is contained in:
Kimmo Varis 2011-03-29 20:31:36 +03:00
parent 0a2f11c2cd
commit 4d4b28b075
2 changed files with 8 additions and 1 deletions

View File

@ -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<std::string> pathParts;
for (; *originalPath; ++originalPath)

View File

@ -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"));