diff options
Diffstat (limited to 'src/Utils.cpp')
-rw-r--r-- | src/Utils.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp index 55fc57e..ae24f7b 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -166,4 +166,22 @@ namespace gsr { fclose(file); return success; } + + std::string get_parent_directory(std::string_view directory) { + std::string result; + + while(directory.size() > 1 && directory.back() == '/') { + directory.remove_suffix(1); + } + + const size_t prev_slash_index = directory.rfind('/'); + if(prev_slash_index == 0) { + result = "/"; + } else if(prev_slash_index == std::string_view::npos) { + result = "."; + } else { + result = directory.substr(0, prev_slash_index); + } + return result; + } }
\ No newline at end of file |