3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-09-30 13:19:05 +00:00

io: use std::filesystem

This commit is contained in:
Emil Jiří Tywoniak 2025-09-23 17:38:14 +02:00
parent d31bfdd66a
commit dad0ffe545

View file

@ -2,6 +2,7 @@
#include "kernel/log.h"
#include <iostream>
#include <string>
#include <filesystem>
#if !defined(WIN32)
#include <dirent.h>
@ -384,23 +385,22 @@ std::string escape_filename_spaces(const std::string& filename)
return out;
}
#ifdef _WIN32
const char* const OS_PATH_SEP = "/\\";
#else
const char* const OS_PATH_SEP = "/";
#endif
std::string name_from_file_path(std::string path) {
size_t sep_pos = path.find_last_of(OS_PATH_SEP);
if (sep_pos != std::string::npos)
return path.substr(sep_pos + 1);
else
return path;
return std::filesystem::path(path).filename().string();
}
// Includes OS_PATH_SEP at the end if present
std::string parent_from_file_path(std::string path) {
return path.substr(0, path.find_last_of(OS_PATH_SEP)+1);
auto parent = std::filesystem::path(path).parent_path();
if (parent.empty()) {
return "";
}
// Add trailing separator to match original behavior
std::string result = parent.string();
if (!result.empty() && result.back() != std::filesystem::path::preferred_separator) {
result += std::filesystem::path::preferred_separator;
}
return result;
}
void format_emit_unescaped(std::string &result, std::string_view fmt)