diff --git a/lib/path.cpp b/lib/path.cpp index 6770267cfda..9317df6e60c 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -175,18 +175,7 @@ std::string Path::getCurrentExecutablePath(const char* fallback) bool Path::isAbsolute(const std::string& path) { -#ifdef _WIN32 - if (path.length() < 2) - return false; - - if ((path[0] == '\\' || path[0] == '/') && (path[1] == '\\' || path[1] == '/')) - return true; - - // On Windows, 'C:\foo\bar' is an absolute path, while 'C:foo\bar' is not - return std::isalpha(path[0]) && path[1] == ':' && (path[2] == '\\' || path[2] == '/'); -#else - return !path.empty() && path[0] == '/'; -#endif + return simplecpp::isAbsolutePath(path); } std::string Path::getRelativePath(const std::string& absolutePath, const std::vector& basePaths) diff --git a/test/testpath.cpp b/test/testpath.cpp index 44d5f10a30b..c07bf777031 100644 --- a/test/testpath.cpp +++ b/test/testpath.cpp @@ -42,7 +42,6 @@ class TestPath : public TestFixture { TEST_CASE(acceptFile); TEST_CASE(getCurrentPath); TEST_CASE(getCurrentExecutablePath); - TEST_CASE(isAbsolute); TEST_CASE(getRelative); TEST_CASE(get_path_from_filename); TEST_CASE(join); @@ -129,26 +128,6 @@ class TestPath : public TestFixture { ASSERT_EQUALS(false, Path::getCurrentExecutablePath("").empty()); } - void isAbsolute() const { -#ifdef _WIN32 - ASSERT_EQUALS(true, Path::isAbsolute("C:\\foo\\bar")); - ASSERT_EQUALS(true, Path::isAbsolute("C:/foo/bar")); - ASSERT_EQUALS(true, Path::isAbsolute("\\\\foo\\bar")); - ASSERT_EQUALS(false, Path::isAbsolute("foo\\bar")); - ASSERT_EQUALS(false, Path::isAbsolute("foo/bar")); - ASSERT_EQUALS(false, Path::isAbsolute("foo.cpp")); - ASSERT_EQUALS(false, Path::isAbsolute("C:foo.cpp")); - ASSERT_EQUALS(false, Path::isAbsolute("C:foo\\bar.cpp")); - ASSERT_EQUALS(false, Path::isAbsolute("bar.cpp")); - TODO_ASSERT_EQUALS(true, false, Path::isAbsolute("\\")); -#else - ASSERT_EQUALS(true, Path::isAbsolute("/foo/bar")); - ASSERT_EQUALS(true, Path::isAbsolute("/")); - ASSERT_EQUALS(false, Path::isAbsolute("foo/bar")); - ASSERT_EQUALS(false, Path::isAbsolute("foo.cpp")); -#endif - } - void getRelative() const { const std::vector basePaths = { "", // Don't crash with empty paths