fix dirname() implementation of Windows in lottieloader.cpp, and fix basename() implementation by using strrchr() and not strchr()

This commit is contained in:
Vincent Torri 2019-07-01 11:23:26 +02:00 committed by Subhransu
parent 71538bac3a
commit ae933c37af
2 changed files with 5 additions and 2 deletions

View File

@ -110,11 +110,11 @@ public:
baseName = absoloutePath; baseName = absoloutePath;
#ifdef _WIN32 #ifdef _WIN32
char *base = strchr(baseName.data(), '/'); char *base = strrchr(baseName.data(), '/');
if (base) if (base)
{ {
base++; base++;
base = strchr(baseName.data(), '\\'); base = strrchr(baseName.data(), '\\');
if (base) base++; if (base) base++;
else return 1; else return 1;
} }

View File

@ -71,6 +71,9 @@ public:
static std::string dirname(const std::string &path) static std::string dirname(const std::string &path)
{ {
const char *ptr = strrchr(path.c_str(), '/'); const char *ptr = strrchr(path.c_str(), '/');
#ifdef _WIN32
if (ptr) ptr = strrchr(ptr + 1, '\\');
#endif
int len = int(ptr + 1 - path.c_str()); // +1 to include '/' int len = int(ptr + 1 - path.c_str()); // +1 to include '/'
return std::string(path, 0, len); return std::string(path, 0, len);
} }