1
1
mirror of https://github.com/rui314/mold.git synced 2024-12-28 19:04:27 +03:00
mold/filepath.cc
2021-03-08 17:24:51 +09:00

25 lines
527 B
C++

#include "mold.h"
std::string path_dirname(std::string_view path) {
i64 pos = path.find_last_of('/');
if (pos == path.npos)
return ".";
return std::string(path.substr(0, pos));
}
std::string path_basename(std::string_view path) {
if (path.empty())
return ".";
while (path.ends_with('/'))
path = path.substr(0, path.size() - 2);
if (path.empty())
return "/";
i64 pos = path.find_last_of('/');
if (pos == path.npos)
return std::string(path);
return std::string(path.substr(pos + 1));
}