From c4d1491af938a12a0167dae4fd3ea8f1810c752a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 25 Sep 2018 20:47:40 +0200 Subject: Fix build for windows --- src/FileUtil.cpp | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'src/FileUtil.cpp') diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp index 53430c4..77669e5 100644 --- a/src/FileUtil.cpp +++ b/src/FileUtil.cpp @@ -489,25 +489,38 @@ namespace sibs } #endif - // TODO: Support better path equality check. For example if path contains several slashes in a row: /home/userName/.sibs//lib////libraryName - // then it should equal: /home/userName/.sibs/lib/libraryName - // Maybe check with OS operation if they refer to the same inode? + // TODO: Support better path equality check. Maybe check with OS operation if they refer to the same inode? bool pathEquals(const std::string &path, const std::string &otherPath) { - if(path.size() != otherPath.size()) - return false; - - size_t size = path.size(); - for(size_t i = 0; i < size; ++i) - { - char c = path[i]; - char otherC = otherPath[i]; - if(c == '\\') c = '/'; - if(otherC == '\\') otherC = '/'; - if(c != otherC) - return false; - } - - return true; + size_t pathIndex = 0; + size_t otherPathIndex = 0; + + while (true) + { + while (pathIndex < path.size() && (path[pathIndex] == '/' || path[pathIndex] == '\\')) + { + ++pathIndex; + } + + while (otherPathIndex < otherPath.size() && (otherPath[otherPathIndex] == '/' || otherPath[otherPathIndex] == '\\')) + { + ++otherPathIndex; + } + + if (pathIndex < path.size() && otherPathIndex < otherPath.size()) + { + if (path[pathIndex] != otherPath[otherPathIndex]) + return false; + + ++pathIndex; + ++otherPathIndex; + } + else + { + break; + } + } + + return pathIndex == path.size() && otherPathIndex == otherPath.size(); } } -- cgit v1.2.3