diff options
Diffstat (limited to 'src/utils/dirname.cpp')
-rw-r--r-- | src/utils/dirname.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/utils/dirname.cpp b/src/utils/dirname.cpp new file mode 100644 index 0000000..71c9c38 --- /dev/null +++ b/src/utils/dirname.cpp @@ -0,0 +1,16 @@ +#include <utils/dirname.hpp> + +namespace utils +{ + std::string dirname(const std::string filename) + { + if (filename.empty()) + return "./"; + if (filename == ".." || filename == ".") + return filename; + auto pos = filename.rfind('/'); + if (pos == std::string::npos) + return "./"; + return filename.substr(0, pos + 1); + } +} |