extended_cpp #2

Merged
Fabel merged 4 commits from extended_cpp into develop 2025-01-19 19:05:18 +00:00
1 changed files with 51 additions and 28 deletions
Showing only changes of commit 6d5610c05c - Show all commits

View File

@ -3,16 +3,23 @@
#include <filesystem> #include <filesystem>
namespace fs = std::filesystem; namespace fs = std::filesystem;
bool TreeStructurer::should_ignore_dir(const std::string& dirname) { bool TreeStructurer::should_ignore_dir(const std::string& dirname) {
static const std::vector<std::string> ignore_list = { static const std::vector<std::string> ignore_list = {
"build", "venv", "myenv", "dist", "node_modules", "CMakeFiles", "build", "venv", "myenv", "dist", "node_modules", "CMakeFiles",
".git", ".idea", ".vscode", "__pycache__" ".git", ".idea", ".vscode", "__pycache__"
}; };
return dirname[0] == '.' || // Ignore directories in the ignore list
dirname[0] == '_' || // This will catch __pycache__ and _directories if (std::find(ignore_list.begin(), ignore_list.end(), dirname) != ignore_list.end()) {
std::find(ignore_list.begin(), ignore_list.end(), dirname) != ignore_list.end(); return true;
}
// Ignore directories starting with '.' or '_'
if (!dirname.empty() && (dirname[0] == '.' || dirname[0] == '_')) {
return true;
}
return false;
} }
bool TreeStructurer::should_ignore_file(const std::string& filename) { bool TreeStructurer::should_ignore_file(const std::string& filename) {
@ -21,11 +28,19 @@ bool TreeStructurer::should_ignore_file(const std::string& filename) {
".o", ".obj", ".a", ".lib" ".o", ".obj", ".a", ".lib"
}; };
if (filename[0] == '.') return true; // Ignore files starting with '.' or '_'
if (!filename.empty() && (filename[0] == '.' || filename[0] == '_')) {
return true;
}
// Ignore files with specific extensions
fs::path path(filename); fs::path path(filename);
std::string ext = path.extension().string(); std::string ext = path.extension().string();
return std::find(ignore_extensions.begin(), ignore_extensions.end(), ext) != ignore_extensions.end(); if (std::find(ignore_extensions.begin(), ignore_extensions.end(), ext) != ignore_extensions.end()) {
return true;
}
return false;
} }
std::vector<fs::path> TreeStructurer::get_filtered_paths(const fs::path& start) { std::vector<fs::path> TreeStructurer::get_filtered_paths(const fs::path& start) {
@ -33,32 +48,40 @@ std::vector<fs::path> TreeStructurer::get_filtered_paths(const fs::path& start)
for (const auto& entry : fs::recursive_directory_iterator(start)) { for (const auto& entry : fs::recursive_directory_iterator(start)) {
const auto& path = entry.path(); const auto& path = entry.path();
bool should_include = true;
// Skip any path that contains an ignored directory
bool contains_ignored_dir = false;
for (auto it = path.begin(); it != path.end(); ++it) { for (auto it = path.begin(); it != path.end(); ++it) {
if (should_ignore_dir(it->string())) { if (should_ignore_dir(it->string())) {
should_include = false; contains_ignored_dir = true;
break; break;
} }
} }
if(should_include) { if (contains_ignored_dir) {
continue;
}
// Handle directories
if (fs::is_directory(path)) { if (fs::is_directory(path)) {
if (!should_ignore_dir(path.filename().string())) { if (!should_ignore_dir(path.filename().string())) {
paths.push_back(path); paths.push_back(path);
} }
} else { }
// Handle files
else {
if (!should_ignore_file(path.filename().string())) { if (!should_ignore_file(path.filename().string())) {
paths.push_back(path); paths.push_back(path);
} }
} }
} }
}
std::sort(paths.begin(), paths.end()); std::sort(paths.begin(), paths.end());
return paths; return paths;
} }
std::string TreeStructurer::create_indent(int level) { std::string TreeStructurer::create_indent(int level) {
if (level == 0) return ""; if (level == 0) return "";