Skip to content

Commit

Permalink
Make path handling OS-agnostic by using std::filesystem::path::prefer…
Browse files Browse the repository at this point in the history
…red_separator
  • Loading branch information
speckdavid committed Jul 18, 2024
1 parent b048352 commit 23db487
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/search/command_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,18 @@ static vector<string> complete_args(
}

// Add file and directory names to suggestions
for (const auto& entry : filesystem::directory_iterator(directory)) {
for (const auto &entry : filesystem::directory_iterator(directory)) {
string path = entry.path().string();

// Append slash to directories
// Append preferred separator ("/" or "\") to directories base on
// operating system
if (entry.is_directory()) {
path += "/";
path += filesystem::path::preferred_separator;
}

// Remove "./" prefix when not present in prefix
if (last_slash_pos == string::npos && directory == "." && path.starts_with("./")) {
path = path.substr(2);
if (last_slash_pos == string::npos && directory == "." && path.starts_with("/\\")) {
path = path.substr(2);
}
suggestions.push_back(path);
}
Expand Down

0 comments on commit 23db487

Please sign in to comment.