2024-11-14 16:04:54 +08:00
|
|
|
#include "of_path.h"
|
|
|
|
#include <filesystem>
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
namespace ofen {
|
|
|
|
COfPath::COfPath()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
COfPath::~COfPath()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-11-29 10:39:00 +08:00
|
|
|
bool COfPath::isSamePath(const ofString& pa, const ofString& pb)
|
2024-11-14 16:04:54 +08:00
|
|
|
{
|
2024-11-29 10:39:00 +08:00
|
|
|
return normalizePath(pa) == normalizePath(pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
ofString COfPath::normalizePath(const ofString& path)
|
|
|
|
{
|
|
|
|
ofString normalized = replaceStr(path, ofT("\\"), ofT("/"));
|
|
|
|
if (!normalized.empty() && normalized.back() == ofT('/')) {
|
|
|
|
normalized.pop_back();
|
|
|
|
}
|
|
|
|
return normalized;
|
|
|
|
}
|
|
|
|
|
|
|
|
ofString COfPath::replaceStr(const ofString& str, const ofString& from, const ofString& to)
|
|
|
|
{
|
|
|
|
if (from.empty()) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
ofString result = str;
|
|
|
|
size_t startPos = 0;
|
|
|
|
while ((startPos = result.find(from, startPos)) != ofString::npos) {
|
|
|
|
result.replace(startPos, from.length(), to);
|
|
|
|
startPos += to.length();
|
|
|
|
}
|
|
|
|
return result;
|
2024-11-14 16:04:54 +08:00
|
|
|
}
|
|
|
|
} // namespace ofen
|