Skip to content

Commit

Permalink
glob does not always search subdirectories (2nd)
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed Jun 6, 2024
1 parent 951be7c commit df650a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/globbing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,13 @@ std::vector<std::string> glob(
auto root = (path.empty() ? "." : path) / "";
const auto path_size = path_to_utf8(root).size();
const auto check_supported_extension = ends_with(pattern, ".*");
const auto recursive = (pattern.find("**") != std::string::npos);
auto checked_files = size_t{ };
for (const auto& part : utf8_to_path(pattern)) {
const auto parts = utf8_to_path(pattern);
for (auto it = parts.begin(); it != parts.end(); ++it) {
const auto& part = *it;
if (path_to_utf8(part).find_first_of("*?") != std::string::npos) {
auto files = std::vector<std::string>();
const auto recursive = (std::next(it) != parts.end());
for_each_file(root, recursive, [&](const std::filesystem::path& file) {
auto file_string = path_to_utf8(file);
file_string.erase(0, path_size);
Expand Down
10 changes: 10 additions & 0 deletions test/test-globbing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ TEST_CASE("globbing - Match") {
CHECK(!match("a", "b"));
CHECK(match("?", "b"));
CHECK(match("?a", "ba"));
CHECK(!match("?a", "a"));
CHECK(!match("a", "a?"));
CHECK(!match("?a", "bb"));
CHECK(!match("?", ""));
CHECK(match("*", ""));
Expand All @@ -33,6 +35,14 @@ TEST_CASE("globbing - Match") {
CHECK(!match("a/**/b", "a/ccc/ddd/bbb"));
CHECK(match("a/**/*b", "a/ccc/ddd/bbb"));
CHECK(!match("a/**/b", "ab"));
CHECK(match("a*/b", "a/b"));
CHECK(match("a*a/b", "aa/b"));
CHECK(match("a*b/b", "acccb/b"));
CHECK(!match("a*b/b", "a/b"));
CHECK(match("a*b/b*", "acccb/b"));
CHECK(match("a*b/b*", "acccb/bccc"));
CHECK(match("a*b/b*a", "acccb/bccca"));
CHECK(!match("a*b/b*a", "b/bccca"));

CHECK(replace_suffix("test-abc.png", "-abc", "-xyz") == "test-xyz.png");
CHECK(replace_suffix("test-abc.png", "-efg", "-xyz") == "test-abc-xyz.png");
Expand Down

0 comments on commit df650a8

Please sign in to comment.