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:
parent
0a2f11c2cd
commit
4d4b28b075
|
@ -47,6 +47,13 @@ std::string Path::fromNativeSeparators(const std::string &path)
|
||||||
|
|
||||||
std::string Path::simplifyPath(const char *originalPath)
|
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::string subPath = "";
|
||||||
std::vector<std::string> pathParts;
|
std::vector<std::string> pathParts;
|
||||||
for (; *originalPath; ++originalPath)
|
for (; *originalPath; ++originalPath)
|
||||||
|
|
|
@ -37,10 +37,10 @@ private:
|
||||||
{
|
{
|
||||||
// Path::simplifyPath()
|
// 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("/index.h", Path::simplifyPath("/index.h"));
|
ASSERT_EQUALS("/index.h", Path::simplifyPath("/index.h"));
|
||||||
ASSERT_EQUALS("/path/", Path::simplifyPath("/path/"));
|
ASSERT_EQUALS("/path/", Path::simplifyPath("/path/"));
|
||||||
ASSERT_EQUALS("/", Path::simplifyPath("/"));
|
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("../index.h"));
|
||||||
ASSERT_EQUALS("/index.h", Path::simplifyPath("/path/../index.h"));
|
ASSERT_EQUALS("/index.h", Path::simplifyPath("/path/../index.h"));
|
||||||
ASSERT_EQUALS("/index.h", Path::simplifyPath("/path/../other/../index.h"));
|
ASSERT_EQUALS("/index.h", Path::simplifyPath("/path/../other/../index.h"));
|
||||||
|
|
Loading…
Reference in New Issue