Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions lib/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>& basePaths)
Expand Down
21 changes: 0 additions & 21 deletions test/testpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<std::string> basePaths = {
"", // Don't crash with empty paths
Expand Down