aboutsummaryrefslogtreecommitdiff
path: root/src/FileUtil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/FileUtil.cpp')
-rw-r--r--src/FileUtil.cpp49
1 files changed, 31 insertions, 18 deletions
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();
}
}