diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-08-25 13:39:33 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-08-25 13:39:33 +0200 |
commit | 3d5e8baa5f66547f1250950b10bd4108e30af423 (patch) | |
tree | 890101088903316749e2843829eb3aa6b67cd3ce /src/Utils.cpp | |
parent | b8e6949dfb8a88c832e82f8b7e853fe0ed462da0 (diff) |
File chooser navigation
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 |