MCPcopy Create free account
hub / github.com/OSGeo/gdal / CPLFixPath

Function CPLFixPath

port/cpl_xml_validate.cpp:76–99  ·  view source on GitHub ↗

Replace \ by / to make libxml2 happy on Windows and replace "a/b/../c" pattern by "a/c".

Source from the content-addressed store, hash-verified

74// Replace \ by / to make libxml2 happy on Windows and
75// replace "a/b/../c" pattern by "a/c".
76static void CPLFixPath(char *pszPath)
77{
78 for (int i = 0; pszPath[i] != '\0'; ++i)
79 {
80 if (pszPath[i] == '\\')
81 pszPath[i] = '/';
82 }
83
84 std::string osRet(pszPath);
85 while (true)
86 {
87 size_t nSlashDotDot = osRet.find("/../");
88 if (nSlashDotDot == std::string::npos || nSlashDotDot == 0)
89 break;
90 size_t nPos = nSlashDotDot - 1;
91 while (nPos > 0 && osRet[nPos] != '/')
92 --nPos;
93 if (nPos == 0)
94 break;
95 osRet = osRet.substr(0, nPos + 1) +
96 osRet.substr(nSlashDotDot + strlen("/../"));
97 }
98 memcpy(pszPath, osRet.data(), osRet.size() + 1);
99}
100
101#ifdef HAS_VALIDATION_BUG
102

Callers 1

CPLLoadSchemaStrInternalFunction · 0.85

Calls 2

dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected