aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/wintermute/utils/path_util.cpp10
-rw-r--r--engines/wintermute/utils/path_util.h1
-rw-r--r--test/engines/wintermute/path_utils.h24
3 files changed, 32 insertions, 3 deletions
diff --git a/engines/wintermute/utils/path_util.cpp b/engines/wintermute/utils/path_util.cpp
index db986061f8..60a07f0bf0 100644
--- a/engines/wintermute/utils/path_util.cpp
+++ b/engines/wintermute/utils/path_util.cpp
@@ -63,6 +63,10 @@ Common::String PathUtil::combine(const Common::String &path1, const Common::Stri
return newPath1 + newPath2;
}
+bool PathUtil::hasTrailingSlash(const Common::String &path) {
+ return (path.size() > 0 && path[path.size() - 1 ] == '/');
+}
+
//////////////////////////////////////////////////////////////////////////
Common::String PathUtil::getDirectoryName(const Common::String &path) {
Common::String newPath = unifySeparators(path);
@@ -74,10 +78,10 @@ Common::String PathUtil::getDirectoryName(const Common::String &path) {
Common::String PathUtil::getFileName(const Common::String &path) {
Common::String newPath = unifySeparators(path);
Common::String lastPart = Common::lastPathComponent(newPath, '/');
- if (lastPart[lastPart.size() - 1 ] != '/') {
- return lastPart;
+ if (hasTrailingSlash(newPath)) {
+ return Common::String("");
} else {
- return path;
+ return lastPart;
}
}
diff --git a/engines/wintermute/utils/path_util.h b/engines/wintermute/utils/path_util.h
index cc64fb9347..8050cdfae2 100644
--- a/engines/wintermute/utils/path_util.h
+++ b/engines/wintermute/utils/path_util.h
@@ -42,6 +42,7 @@ public:
static Common::String getFileName(const Common::String &path);
static Common::String getFileNameWithoutExtension(const Common::String &path);
static Common::String getExtension(const Common::String &path);
+ static bool hasTrailingSlash(const Common::String &path);
};
} // End of namespace Wintermute
diff --git a/test/engines/wintermute/path_utils.h b/test/engines/wintermute/path_utils.h
index c3f1776231..3cacf47fd9 100644
--- a/test/engines/wintermute/path_utils.h
+++ b/test/engines/wintermute/path_utils.h
@@ -53,6 +53,10 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
Wintermute::PathUtil::getDirectoryName(windowsCapPath),
Common::String("C:\\SOME\\")
);
+ TS_ASSERT_EQUALS(
+ Wintermute::PathUtil::getDirectoryName(emptyString),
+ Common::String("")
+ );
}
void test_getfilename() {
@@ -73,6 +77,10 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
Common::String("FILE.EXT")
);
TS_ASSERT_EQUALS(
+ Wintermute::PathUtil::getFileName(emptyString),
+ Common::String("")
+ );
+ TS_ASSERT_EQUALS(
Wintermute::PathUtil::getFileName(unixRelativePath),
Common::String("file.ext")
);
@@ -80,6 +88,14 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
Wintermute::PathUtil::getFileName(windowsRelativePath),
Common::String("file.ext")
);
+ TS_ASSERT_EQUALS(
+ Wintermute::PathUtil::getFileName(windowsDirPath),
+ Common::String("")
+ );
+ TS_ASSERT_EQUALS(
+ Wintermute::PathUtil::getFileName(unixDirPath),
+ Common::String("")
+ );
}
void test_getextension() {
@@ -92,6 +108,10 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
Common::String("EXT")
);
TS_ASSERT_EQUALS(
+ Wintermute::PathUtil::getExtension(emptyString),
+ Common::String("")
+ );
+ TS_ASSERT_EQUALS(
Wintermute::PathUtil::getExtension(dualExtPath),
Common::String("gz")
);
@@ -119,6 +139,10 @@ class PathUtilTestSuite : public CxxTest::TestSuite {
Common::String("FILE")
);
TS_ASSERT_EQUALS(
+ Wintermute::PathUtil::getFileNameWithoutExtension(emptyString),
+ Common::String("")
+ );
+ TS_ASSERT_EQUALS(
Wintermute::PathUtil::getFileNameWithoutExtension(dualExtPath),
Common::String("file.tar")
);