From 3d5e8baa5f66547f1250950b10bd4108e30af423 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 25 Aug 2024 13:39:33 +0200 Subject: File chooser navigation --- src/Utils.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/Utils.cpp') 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 -- cgit v1.2.3