From 6f1a4a73b754810408cfbb449d0c71e63b762e82 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 27 Oct 2020 18:58:25 +0100 Subject: [PATCH] fs/Traits: add GetFilenameSuffix() --- src/fs/Traits.hxx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/fs/Traits.hxx b/src/fs/Traits.hxx index da899df63..b61de1833 100644 --- a/src/fs/Traits.hxx +++ b/src/fs/Traits.hxx @@ -88,6 +88,14 @@ struct PathTraitsFS { #endif } + gcc_pure + static const_pointer GetFilenameSuffix(const_pointer filename) noexcept { + const_pointer dot = StringFindLast(filename, '.'); + return dot != nullptr && dot > filename && dot[1] != 0 + ? dot + 1 + : nullptr; + } + #ifdef _WIN32 gcc_pure gcc_nonnull_all static constexpr bool IsDrive(const_pointer p) noexcept { @@ -199,6 +207,14 @@ struct PathTraitsUTF8 { return std::strrchr(p, SEPARATOR); } + gcc_pure + static const_pointer GetFilenameSuffix(const_pointer filename) noexcept { + const_pointer dot = StringFindLast(filename, '.'); + return dot != nullptr && dot > filename && dot[1] != 0 + ? dot + 1 + : nullptr; + } + #ifdef _WIN32 gcc_pure gcc_nonnull_all static constexpr bool IsDrive(const_pointer p) noexcept {