From 23db48796918909ff495dec3597a82ffe7e722db Mon Sep 17 00:00:00 2001 From: speckdavid Date: Thu, 18 Jul 2024 09:39:16 +0200 Subject: [PATCH] Make path handling OS-agnostic by using std::filesystem::path::preferred_separator --- src/search/command_line.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/search/command_line.cc b/src/search/command_line.cc index 4bb3922a20..2b728d894c 100644 --- a/src/search/command_line.cc +++ b/src/search/command_line.cc @@ -210,17 +210,18 @@ static vector 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); }