fs/Path: add GetSuffix()
This commit is contained in:
@@ -295,6 +295,15 @@ public:
|
||||
return Traits::Relative(c_str(), other_fs.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename suffix (including the dot) or nullptr
|
||||
* if the path does not have one.
|
||||
*/
|
||||
[[gnu::pure]]
|
||||
const_pointer GetSuffix() const noexcept {
|
||||
return Path{*this}.GetSuffix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename extension (excluding the dot) or
|
||||
* nullptr if the path does not have one.
|
||||
|
@@ -37,7 +37,7 @@ Path::ToUTF8Throw() const
|
||||
}
|
||||
|
||||
Path::const_pointer
|
||||
Path::GetExtension() const noexcept
|
||||
Path::GetSuffix() const noexcept
|
||||
{
|
||||
const auto *base = GetBase().c_str();
|
||||
|
||||
@@ -46,9 +46,16 @@ Path::GetExtension() const noexcept
|
||||
while (*base == '.')
|
||||
++base;
|
||||
|
||||
const auto *dot = StringFindLast(base, '.');
|
||||
if (dot == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return dot + 1;
|
||||
return StringFindLast(base, '.');
|
||||
}
|
||||
|
||||
Path::const_pointer
|
||||
Path::GetExtension() const noexcept
|
||||
{
|
||||
const auto *result = GetSuffix();
|
||||
if (result != nullptr)
|
||||
/* skip the dot */
|
||||
++result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -166,6 +166,13 @@ public:
|
||||
return Traits::IsAbsolute(c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename suffix (including the dot) or nullptr
|
||||
* if the path does not have one.
|
||||
*/
|
||||
[[gnu::pure]]
|
||||
const_pointer GetSuffix() const noexcept;
|
||||
|
||||
/**
|
||||
* Returns the filename extension (excluding the dot) or
|
||||
* nullptr if the path does not have one.
|
||||
|
Reference in New Issue
Block a user