From a34bcc790bc0cc5f7e3800b122c155dbb32f6065 Mon Sep 17 00:00:00 2001 From: codereader Date: Mon, 6 Jan 2020 18:50:11 +0100 Subject: [PATCH] Change os::getFilename to return the input string when there's no slash to be found --- libs/os/path.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libs/os/path.h b/libs/os/path.h index fcc019fef2..7c44a3ca24 100644 --- a/libs/os/path.h +++ b/libs/os/path.h @@ -146,17 +146,15 @@ namespace os /** * greebo: Get the filename contained in the given path (the part after the last slash). * If there is no filename, an empty string is returned. + * If there's no slash, the input string is returned as is. * * Note: The input string is expected to be standardised (forward slashes). */ - inline std::string getFilename(const std::string& path) { + inline std::string getFilename(const std::string& path) + { std::size_t slashPos = path.rfind('/'); - if (slashPos == std::string::npos) { - return ""; - } - else { - return path.substr(slashPos + 1); - } + + return slashPos == std::string::npos ? path : path.substr(slashPos + 1); } /**