From 20bbe1b57b3349c20ca17d675444b1f8a8edb76f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 6 Sep 2023 14:50:34 +0200 Subject: [PATCH] fs/Traits: add GetFilenameSuffix() overload with std::string_view --- src/fs/Traits.hxx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/fs/Traits.hxx b/src/fs/Traits.hxx index c14aa3f08..57f4814b0 100644 --- a/src/fs/Traits.hxx +++ b/src/fs/Traits.hxx @@ -92,6 +92,14 @@ struct PathTraitsFS { : nullptr; } + [[gnu::pure]] + static string_view GetFilenameSuffix(string_view filename) noexcept { + const auto dot = filename.rfind('.'); + return dot != filename.npos && dot > 0 + ? filename.substr(dot + 1) + : string_view{}; + } + [[gnu::pure]] static const_pointer GetPathSuffix(const_pointer path) noexcept { return GetFilenameSuffix(GetBase(path)); @@ -228,6 +236,14 @@ struct PathTraitsUTF8 { : nullptr; } + [[gnu::pure]] + static string_view GetFilenameSuffix(string_view filename) noexcept { + const auto dot = filename.rfind('.'); + return dot != filename.npos && dot > 0 + ? filename.substr(dot + 1) + : string_view{}; + } + [[gnu::pure]] static const_pointer GetPathSuffix(const_pointer path) noexcept { return GetFilenameSuffix(GetBase(path));