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));