Always use correct path separator when normalizing

This commit is contained in:
Roza 2020-12-17 15:47:18 -05:00
parent 3abbc7e21f
commit 6bf1913a09
2 changed files with 16 additions and 5 deletions

View file

@ -74,13 +74,23 @@ std::string filesystemImpl::normalizePath(const char *path, bool preferred, bool
stdPath.lexically_normal();
std::string ret(stdPath);
for (int i = 0; i < ret.length(); i++) {
char sep;
char sep_alt;
#ifdef __WINDOWS__
if (!preferred) {
for (int i = 0; i < ret.length(); i++) {
if (ret[i] == '\\')
ret[i] = '/';
if (!preferred) {
sep = '\\';
sep_alt = '/';
}
}
else
#endif
{
sep = '/';
sep_alt = '\\';
}
if (ret[i] == sep_alt)
ret[i] = sep;
}
return ret;
}

View file

@ -45,6 +45,7 @@ std::string filesystemImpl::normalizePath(const char *path, bool preferred, bool
if (!absolute) {
nspath = [nspath stringByReplacingOccurrencesOfString:pwd withString:@""];
}
nspath = [nspath stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
return std::string(NSTOPATH(nspath));
}