Skip to content

Commit

Permalink
Fix basename util function on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Oipo committed Feb 2, 2024
1 parent 995b669 commit ac02fbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/ichor/stl/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ namespace Ichor {
#ifdef _WIN32
const std::reverse_iterator<const char *> begin(filename + std::strlen(filename));
const std::reverse_iterator<const char *> end(filename);
const std::string_view seperator{"\\/"};

const auto it = std::find_first_of(begin, end, std::begin("\\/"),
std::end("\\/") - 1);
const auto it = std::find_first_of(begin, end, std::begin(seperator), std::end(seperator));
return it != end ? it.base() : filename;
#else
const char *rv = std::strrchr(filename, '/');
Expand Down
5 changes: 5 additions & 0 deletions test/StlTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,13 @@ TEST_CASE("STL Tests") {
}

SECTION("Basename tests") {
REQUIRE(Ichor::basename("") == ""sv);
REQUIRE(Ichor::basename("file.cpp") == "file.cpp"sv);
#ifdef _WIN32
REQUIRE(Ichor::basename("path\\file.cpp") == "file.cpp"sv);
#else
REQUIRE(Ichor::basename("path/file.cpp") == "file.cpp"sv);
REQUIRE(Ichor::basename("more/path/file.cpp") == "file.cpp"sv);
#endif
}
}

0 comments on commit ac02fbe

Please sign in to comment.