30 lines
622 B
C++
30 lines
622 B
C++
#ifndef UTILS_H
|
|
#define UTILS_H
|
|
|
|
#include <string>
|
|
|
|
inline std::string basedir(const std::string &path)
|
|
{
|
|
int idx1 = path.rfind("/");
|
|
int idx2 = path.rfind("\\");
|
|
std::string r;
|
|
if (idx1 == std::string::npos && idx2 == std::string::npos) {
|
|
r = "";
|
|
} else {
|
|
int idx;
|
|
if (idx1 == std::string::npos) {
|
|
idx = idx2;
|
|
} else if (idx2 == std::string::npos) {
|
|
idx = idx1;
|
|
} else if (idx1 < idx2) {
|
|
idx = idx2;
|
|
} else {
|
|
idx = idx1;
|
|
}
|
|
r = path.substr(0, idx);
|
|
}
|
|
return r;
|
|
}
|
|
|
|
#endif // UTILS_H
|