fs/Traits: add GetFilenameSuffix() overload with std::string_view

This commit is contained in:
Max Kellermann 2023-09-06 14:50:34 +02:00
parent 449d59af2f
commit 20bbe1b57b
1 changed files with 16 additions and 0 deletions

View File

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