From 664c340d84deeeffddd0d043e5cd4b5c5b7f136c Mon Sep 17 00:00:00 2001 From: docentYT <63965954+docentYT@users.noreply.github.com> Date: Fri, 1 May 2026 13:45:57 +0200 Subject: [PATCH] substr_path refactor --- utilities/utilities.cpp | 6 +++--- utilities/utilities.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/utilities/utilities.cpp b/utilities/utilities.cpp index 3be4118e..269468d5 100644 --- a/utilities/utilities.cpp +++ b/utilities/utilities.cpp @@ -391,10 +391,10 @@ void replace_slashes(std::string &Filename) } // returns potential path part from provided file name -std::string substr_path(std::string const &Filename) +std::string_view substr_path(std::string const &Filename) { - - return (Filename.rfind('/') != std::string::npos ? Filename.substr(0, Filename.rfind('/') + 1) : ""); + if (auto pos = Filename.rfind('/'); pos != std::string_view::npos) + return Filename.substr(0, pos + 1); } // returns length of common prefix between two provided strings diff --git a/utilities/utilities.h b/utilities/utilities.h index e540fc98..2b1e61c7 100644 --- a/utilities/utilities.h +++ b/utilities/utilities.h @@ -221,7 +221,7 @@ void erase_leading_slashes(std::string &Filename); void replace_slashes(std::string &Filename); // returns potential path part from provided file name -std::string substr_path(std::string const &Filename); +std::string_view substr_path(std::string const &Filename); // returns common prefix of two provided strings std::ptrdiff_t len_common_prefix(std::string const &Left, std::string const &Right);