mirror of
https://github.com/YosysHQ/yosys
synced 2025-10-16 20:40:29 +00:00
io: use std::filesystem
This commit is contained in:
parent
5cfe6a9c1e
commit
79cd4e08c4
1 changed files with 12 additions and 6 deletions
18
kernel/io.cc
18
kernel/io.cc
|
@ -2,6 +2,7 @@
|
|||
#include "kernel/log.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
#if !defined(WIN32)
|
||||
#include <dirent.h>
|
||||
|
@ -398,16 +399,21 @@ 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue