summaryrefslogtreecommitdiff
path: root/src/utils/dirname.cpp
blob: 71c9c38c1c6a58a394288efd18455df53d24d866 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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);
    }
}