From 09f83e48ffec56ab5182925bb6876375c6373a39 Mon Sep 17 00:00:00 2001 From: Eladash Date: Sat, 24 Jun 2023 10:37:01 +0300 Subject: [PATCH] fs: Add get_parent_dir_view string view version of the argument path, use with care. --- Utilities/File.cpp | 4 ++-- Utilities/File.h | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index 04061da85f..c8e4622811 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -385,7 +385,7 @@ shared_ptr fs::set_virtual_device(const std::string& name, shar return get_device_manager().set_device(name, std::move(device)); } -std::string fs::get_parent_dir(std::string_view path, u32 parent_level) +std::string_view fs::get_parent_dir_view(std::string_view path, u32 parent_level) { std::string_view result = path; @@ -433,7 +433,7 @@ std::string fs::get_parent_dir(std::string_view path, u32 parent_level) return "/"; } - return std::string{result}; + return result; } bool fs::stat(const std::string& path, stat_t& info) diff --git a/Utilities/File.h b/Utilities/File.h index 55fbd05998..ce20ccdb95 100644 --- a/Utilities/File.h +++ b/Utilities/File.h @@ -166,7 +166,13 @@ namespace fs shared_ptr set_virtual_device(const std::string& name, shared_ptr device); // Try to get parent directory - std::string get_parent_dir(std::string_view path, u32 parent_level = 1); + std::string_view get_parent_dir_view(std::string_view path, u32 parent_level = 1); + + // String (typical use) version + inline std::string get_parent_dir(std::string_view path, u32 parent_level = 1) + { + return std::string{get_parent_dir_view(path, parent_level)}; + } // Get file information bool stat(const std::string& path, stat_t& info);