mirror of
https://github.com/YosysHQ/yosys
synced 2025-09-30 13:19:05 +00:00
reduce OS ifdefs, refactor getting dirs and filenames from paths to files
This commit is contained in:
parent
e8f8297e5d
commit
d31bfdd66a
5 changed files with 25 additions and 26 deletions
19
kernel/io.cc
19
kernel/io.cc
|
@ -384,6 +384,25 @@ 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;
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
void format_emit_unescaped(std::string &result, std::string_view fmt)
|
||||
{
|
||||
result.reserve(result.size() + fmt.size());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue