diff --git a/include/of_path.h b/include/of_path.h index ed8fdd1..e7897ef 100644 --- a/include/of_path.h +++ b/include/of_path.h @@ -11,7 +11,9 @@ public: ~COfPath(); public: - static bool is_same_path(const ofString& pa, const ofString& pb); + static bool isSamePath(const ofString& pa, const ofString& pb); + static ofString normalizePath(const ofString& path); + static ofString replaceStr(const ofString& str, const ofString& from, const ofString& to); }; }; // namespace ofen #endif \ No newline at end of file diff --git a/src/of_path.cpp b/src/of_path.cpp index bec68e4..0da8c2e 100644 --- a/src/of_path.cpp +++ b/src/of_path.cpp @@ -11,8 +11,31 @@ COfPath::~COfPath() { } -bool COfPath::is_same_path(const ofString& pa, const ofString& pb) +bool COfPath::isSamePath(const ofString& pa, const ofString& pb) { - return false; + 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; } } // namespace ofen