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(); stdPath.lexically_normal();
std::string ret(stdPath); std::string ret(stdPath);
for (int i = 0; i < ret.length(); i++) {
char sep;
char sep_alt;
#ifdef __WINDOWS__ #ifdef __WINDOWS__
if (!preferred) { if (!preferred) {
for (int i = 0; i < ret.length(); i++) { sep = '\\';
if (ret[i] == '\\') sep_alt = '/';
ret[i] = '/';
} }
} else
#endif #endif
{
sep = '/';
sep_alt = '\\';
}
if (ret[i] == sep_alt)
ret[i] = sep;
}
return ret; return ret;
} }

View file

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