Codechange: use C++ strings for constructing script file paths

This commit is contained in:
Rubidium
2023-05-06 13:22:16 +02:00
committed by rubidium42
parent 20ff0bccd7
commit 98972a0748
5 changed files with 12 additions and 17 deletions

View File

@@ -53,18 +53,14 @@ SQInteger SquirrelStd::require(HSQUIRRELVM vm)
return SQ_ERROR;
}
char path[MAX_PATH];
strecpy(path, si.source, lastof(path));
/* Keep the dir, remove the rest */
SQChar *s = strrchr(path, PATHSEPCHAR);
if (s != nullptr) {
/* Keep the PATHSEPCHAR there, remove the rest */
s++;
*s = '\0';
}
strecat(path, filename, lastof(path));
std::string path = si.source;
auto p = path.find_last_of(PATHSEPCHAR);
/* Keep the PATHSEPCHAR there, remove the rest */
if (p != std::string::npos) path.erase(p + 1);
path += filename;
#if (PATHSEPCHAR != '/')
for (char *n = path; *n != '\0'; n++) if (*n == '/') *n = PATHSEPCHAR;
std::transform(path.begin(), path.end(), path.begin(), [](char &c) { return c == '/' ? PATHSEPCHAR : c; });
#endif
Squirrel *engine = (Squirrel *)sq_getforeignptr(vm);